[英]How to Update ENV variable permanently in jenkins through jenkinsfile, to be used in successful builds
need my ENV variable to update its value through jenkinsfile and be able to use the updated value in next jenkinsbuild需要我的 ENV 变量通过 jenkinsfile 更新它的值,并能够在下一个 jenkinsbuild 中使用更新后的值
I created an Environment variable on the jenkins node我在 jenkins 节点上创建了一个环境变量
enter image description here在此处输入图像描述
I'm updating the variable,getting this output `我正在更新变量,得到这个 output`
println "${env.EOD_ID}"
env.EOD_ID = "23ba9d9e-93ce-4b46-a81d-8784794d81b1-test"
println "${env.EOD_ID}"
` `
output: output:
test
10:29:31 [Pipeline] echo
10:29:31 23ba9d9e-93ce-4b46-a81d-8784794d81b1-test
but when i run the next build it does not have the value 23ba9d9e-93ce-4b46-a81d-8784794d81b1-test但是当我运行下一个版本时,它没有值 23ba9d9e-93ce-4b46-a81d-8784794d81b1-test
You can't update the environment variables like that.您不能那样更新环境变量。 If you are using the EnvInject Plugin you can use the following script to update the Environment variable.如果您使用的是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.