问题
In my jenkins pipeline I am working with properties stored in file.
I can read properties from file and add new items to the map using this code, but I do not understand how to persist my changes.
node('hozuki-best-girl') {
def propertiesPath = "${env.hozuki_properties}"
def props = readProperties file: propertiesPath
props['versionCode'] = 100500
}
What should I do in order to persist my changes? There is no writeProperties method here https://jenkins.io/doc/pipeline/steps/pipeline-utility-steps/#code-readproperties-code-read-properties-from-files-in-the-workspace-or-text
回答1:
you can use yaml format instead of properties.
it also simple and human readable and in jenkins-pipeline there are read and write operations for yaml
or you can use this kind of code:
@NonCPS
def propsToString(Map map){
return new StringWriter().with{w-> (map as Properties).store(w, null); w; }.toString()
}
writeFile file: propertiesPath, text: propsToString(props)
回答2:
The Phoenix AutoTest Plugin has a writeProperties
step.
来源:https://stackoverflow.com/questions/48400140/how-to-persist-properties-in-jenkins-pipeline