[英]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.