XmlSlurper的问题

时间:2018-10-29 18:33:20

标签: jenkins groovy jenkins-pipeline pipeline

我需要从2个xml文件中读取数据。我有以下管道脚本:

            def targetServerConfigFileContent = readFile file: 'apiproxy/targets/default.xml'               
            def xmlObject1 = new XmlSlurper().parseText(targetServerConfigFileContent);

            echo "-------------"
            existingTargetServerName = xmlObject1.HTTPTargetConnection.LoadBalancer.Server.'@name';

            echo "existingTargetServerName::${existingTargetServerName}"

            targetServerConfigFileContent = null;
            xmlObject1 = null;

            def proxyConfigFileContent = readFile file: 'apiproxy/'+ proxyName + '.xml'
            def xmlObject = new XmlSlurper().parseText(proxyConfigFileContent);

            existingProxyName = xmlObject.'@name'
            existingBasePath = xmlObject.Basepaths              
            existingProxyDesc = xmlObject.Description

            echo "existingProxyName::${existingProxyName}"
            echo "existingProxyDesc::${existingProxyDesc}"
            echo "existingBasePath::${existingBasePath}"

            proxyConfigFileContent = null;
            xmlObject = null;

此刻,我开始用代码读取第二个文件,它开始引发异常。

def proxyConfigFileContent = readFile file: 'apiproxy/'+ proxyName + '.xml'

例外:

  

java.lang.IllegalArgumentException:无法实例化{message = java.io.NotSerializableException:   groovy.util.slurpersupport.Attributes}用于EchoStep(消息:字符串):   java.lang.ClassCastException:   org.jenkinsci.plugins.workflow.steps.EchoStep.message需要类   java.lang.String但收到类java.io.NotSerializableException

请让我知道代码出了什么问题。

0 个答案:

没有答案