How to persist Properties in jenkins pipeline?

南楼画角 提交于 2021-01-27 23:11:14

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!