我有读取 pom.xml 文件的代码,然后尝试重新序列化并将其写回:
// 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 变量转换为字符串。我尝试应用 .text() 方法,该方法会出现 jenkins 沙箱安全错误。有没有其他人能够从 Jenkins 管道中运行的 groovy 脚本成功编写 XML 文件?
顺便说一句,我也尝试过使用 File 对象,但这在 jenkins 节点之间是不可远程的。只要作业始终在 master 上运行,它就可以工作。