我有一个如下所示的Servers.xml文件
<Servers>
<Environment id="1" name="Jenkins">
<Server id="1" ip="192.168.0.1" />
<Server id="2" ip="10.21.22.30" />
</Environment>
<Environment id="2" name="Pipe">
<Server id="1" ip="192.10.2.77" />
<Server id="2" ip="122.30.45.99" />
</Environment>
</Servers>
我想根据环境标签name
更改ip的值。我搜索了一些答案,但大多数答案都使用XmlSlurper
或XmlParser
,不幸的是,Jenkins管道中不允许使用这两种方法,我得到了
Scripts not permitted to use new groovy.util.XmlSlurper. Administrators can decide whether to approve or reject this signature.
我的问题是,除了XmlSlurper
和XmlParser
,是否有其他方法可以解析管道中的xml文件?
我没有权限允许以上两种方式,我也没有权限下载插件。
谢谢你,谢谢你
我试过了
def fileContent = readFile xmlFile
// def xml = new XmlParser().parseText(fileContent)
// def xml = new XmlSlurper().parseText(fileContent)
xml.Environment.each {...}
和
@NonCPS
String extractFromXml(String xml) {
def node = new XmlSlurper().parseText(xml)
return node
}
以上我都得到了
Scripts not permitted to use new groovy.util.XmlSlurper. Administrators can decide whether to approve or reject this signature.
现在我不想使用XmlParser或XmlSlurper,所以我想知道是否有其他方法可以在管道中解析xml文件。
1条答案
按热度按时间anauzrmj1#
最后我用powershell脚本来做这件事。