简体   繁体   中英

Can I update a Jenkins Global Environment Variable from a pipeline script?

If I define an environment variable (eg. VersionNum) under Jenkins Global Properties, can I update the value within a pipeline script? I was hoping to use it to store version information and update according to script execution results.

What I want to do is write a pipeline script like:

node {
    stage {'Stage1') {
        VersionNum = '5'
    }
}

that will update the global environment variable so the new value that will persist and can be used by other Jenkins jobs.

Rather than try to use the global environment variable, I read a properties file with the Pipeline Utility Steps plugin:

def props = readProperties  file:"${WORKSPACE}\\BuildVersion.properties" 
MajVersion = props['MAJOR_VERSION'].trim()
MinVersion = props['MINOR_VERSION'].trim()

Then if I change a value, I write it back with:

bat "(echo MAJOR_VERSION=${MajVersion} && echo MINOR_VERSION=${MinVersion}) \u003E \"%WORKSPACE%\\BuildVersion.properties\""

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM