简体   繁体   English

我可以从管道脚本更新Jenkins全局环境变量吗?

[英]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? 如果我在Jenkins Global Properties下定义环境变量(例如VersionNum),我可以更新管道脚本中的值吗? 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. 这将更新全局环境变量,以便新的值将持续存在并可供其他Jenkins作业使用。

Rather than try to use the global environment variable, I read a properties file with the Pipeline Utility Steps plugin: 我没有尝试使用全局环境变量,而是使用Pipeline Utility Steps插件读取属性文件:

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\""

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Jenkinsfile的管道阶段内更新Jenkins Properties全局环境变量 - How to update a Jenkins Properties Global Environment Variable from within a pipeline stage in Jenkinsfile 从阶段级别更新 Jenkins 管道中的环境全局变量 - 有可能吗? - Updating environment global variable in Jenkins pipeline from the stage level - is it possible? 如何在 Jenkins 中永久使用 Groovy PostBuild 更新全局环境变量并在其他后续构建中使用它? - How can I update a global Environment Variable using Groovy PostBuild in Jenkins permanently and use it in other subsequent builds? 在流水线 SH 脚本中使用 Jenkins 环境变量 - Using Jenkins Environment Variable in Pipeline SH script 如何通过Jenkins Pipeline插件中的groovy脚本访问全局环境 - How to access global environment through groovy script in Jenkins Pipeline Plugin Jenkins管道中的环境变量 - Environment variable in Jenkins Pipeline jenkins管道-从作业中获取环境变量 - jenkins pipeline - to get the environment variable from a job 从Jenkins Pipeline scrit看不到的环境变量 - Environment variable not seen from Jenkins Pipeline scrit 从Jenkins插件公开全局环境变量 - Expose global environment variable from Jenkins plugin 从 jenkins 管道中的脚本运行 liquibase 更新 - Running liquibase update from script in jenkins pipeline
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM