使用groovy修改xml(JenkinsFile) [英] modifying xml using groovy (JenkinsFile)
本文介绍了使用groovy修改xml(JenkinsFile)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 context.xml 文件. context.xml 的内容如下所示
I have a context.xml file. The content of context.xml is as given below
<?xml version='1.0' encoding='utf-8'?>
<Context>
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<Manager className="com.amazonaws.services.dynamodb.sessionmanager.DynamoDBSessionManager"
awsAccessKey=""
awsSecretKey=""
table="MyTable"
regionId="us-east-1"
createIfNotExist="true" />
</Context>
使用JenkinsFile(常规),我需要将值添加到 awsAccessKey 和 awsSecretKey ,并更新到 context.xml
Using JenkinsFile (groovy) I need to add the values to awsAccessKey and awsSecretKey, and updates to context.xml
我们可以在Jenkinsfile中使用常规的Groovy代码进行文件操作吗?
Can we use normal groovy code in Jenkinsfile for file operations?
有人可以帮我吗
推荐答案
您可以为此使用Groovy的XmlSlurper
,只需在解析后更改属性的内容,然后将其重新序列化回文件即可,如下所示:
You can use Groovy's XmlSlurper
for that and just change the content of the property after parsing and then re-serialize it back to the file, like this:
def slurper = new groovy.util.XmlSlurper().parseText(xmlOriginal)
slurper.Manager.@awsAccessKey = "Meow"
slurper.Manager.@awsSecretKey = "Woof"
def xmlModified = groovy.xml.XmlUtil.serialize(slurper)
new File("context.xml") << xmlModified
这篇关于使用groovy修改xml(JenkinsFile)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文