如何在jenkins管道中持久化属性?
在我的jenkins管道中,我正在处理存储在文件中的属性 我可以使用此代码从文件中读取属性并向映射中添加新项,但我不知道如何持久保存更改如何在jenkins管道中持久化属性?,jenkins,groovy,continuous-integration,jenkins-pipeline,continuous-deployment,Jenkins,Groovy,Continuous Integration,Jenkins Pipeline,Continuous Deployment,在我的jenkins管道中,我正在处理存储在文件中的属性 我可以使用此代码从文件中读取属性并向映射中添加新项,但我不知道如何持久保存更改 node('hozuki-best-girl') { def propertiesPath = "${env.hozuki_properties}" def props = readProperties file: propertiesPath props['versionCode'] = 100500 } 我应该怎么做才能坚持我的更
node('hozuki-best-girl') {
def propertiesPath = "${env.hozuki_properties}"
def props = readProperties file: propertiesPath
props['versionCode'] = 100500
}
我应该怎么做才能坚持我的更改?这里没有writeProperties方法您可以使用yaml格式而不是属性 它也简单易读,在jenkins管道中有yaml的读写操作 或者您可以使用这种代码:
@NonCPS
def propsToString(Map map){
return new StringWriter().with{w-> (map as Properties).store(w, null); w; }.toString()
}
writeFile file: propertiesPath, text: propsToString(props)
有一个
writeProperties
步骤。如果您有解决方案,请与他人共享。writeYaml只能写入一个新文件,无法覆盖现有文件,因此没有必要使用它。