[英]How can I update a global Environment Variable using Groovy PostBuild in Jenkins permanently and use it in other subsequent builds?
[英]How to Update ENV variable permanently in jenkins through jenkinsfile, to be used in successful builds
需要我的 ENV 变量通过 jenkinsfile 更新它的值,并能够在下一个 jenkinsbuild 中使用更新后的值
我在 jenkins 节点上创建了一个环境变量
我正在更新变量,得到这个 output`
println "${env.EOD_ID}"
env.EOD_ID = "23ba9d9e-93ce-4b46-a81d-8784794d81b1-test"
println "${env.EOD_ID}"
`
output:
test
10:29:31 [Pipeline] echo
10:29:31 23ba9d9e-93ce-4b46-a81d-8784794d81b1-test
但是当我运行下一个版本时,它没有值 23ba9d9e-93ce-4b46-a81d-8784794d81b1-test
您不能那样更新环境变量。 如果您使用的是EnvInject 插件,则可以使用以下脚本来更新环境变量。
ef persistInfo(){
def jenkins = Jenkins.instance
def jobA = jenkins.getItemByFullName("$JOB_NAME")
def prop2 = jobA.getProperty(org.jenkinsci.plugins.envinject.EnvInjectJobProperty);
def con = prop2.getInfo().getPropertiesContent();
def str = "NewValue"
def prop = new EnvInjectJobPropertyInfo("", str , "", "", "", false)
def propNew = new org.jenkinsci.plugins.envinject.EnvInjectJobProperty(prop)
propNew.setOn(true)
propNew.setKeepBuildVariables(true)
propNew.setKeepJenkinsSystemVariables(true)
jobA.addProperty(propNew)
jobA.save();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.