2016-12-15 236 views
1

我有一些代碼在一個pom.xml文件中讀取然後嘗試重新序列,並將其寫回:詹金斯:java.io.NotSerializableException:groovy.util.slurpersupport.NodeChild

// Get the file raw text 

def pomXMLText = readFile(pomFile) 

// Parse the pom.xml file 

def project = new XmlSlurper(false, false).parseText(pomXMLText) 

... do some useful stuff ... 

def pomFileOut = "$WORKSPACE/pomtest.xml" 

def pomXMLTextOut = groovy.xml.XmlUtil.serialize(project) 

println "pomXMLTextOut = $pomXMLTextOut" // <-- This line prints to updated XML 

WriteFile的文件:pomFileOut,文本:pomXMLTextOut // < - 這符合在帖子標題中列出的錯誤崩潰:java.io.NotSerializableException:groovy.util.slurpersupport.NodeChild

我已經試過鑄造pomXMLTextOut變量爲一個String。我嘗試應用.text()方法,該方法獲取jenkins沙箱安全性錯誤。其他人是否能夠成功地從運行在Jenkins管道中的groovy腳本編寫XML文件?

順便說一句,我也試過使用一個File對象,但這不是jenkins節點之間的遠程控制。只要作業始終在主控上運行,它就會工作。

回答

0

你可以嘗試@NonCPS註釋,並在funcation關閉那些非序列化對象這樣

@NonCPS 
def writeToFile(String text) { 
    ... 
} 

下面是Pipeline groovy plugin

的解釋

@NonCPS方法可以安全地使用非序列物體爲本地 變量