简体   繁体   English

如何通过 jenkinsfile 在 jenkins 中永久更新 ENV 变量,以用于成功构建

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

相关问题 如何在 Jenkins 中永久使用 Groovy PostBuild 更新全局环境变量并在其他后续构建中使用它? - How can I update a global Environment Variable using Groovy PostBuild in Jenkins permanently and use it in other subsequent builds? 如何将数组分配给Jenkinsfile中的Env变量 - How to assign an array to a Env variable in Jenkinsfile 如何在Jenkinsfile if语句中使用jenkins环境变量 - How to use jenkins environment variable in Jenkinsfile if statement 如何在Jenkinsfile的管道阶段内更新Jenkins Properties全局环境变量 - How to update a Jenkins Properties Global Environment Variable from within a pipeline stage in Jenkinsfile Jenkins - 如何从另一个项目的成功构建中列出构建选择 - Jenkins - How to list build choices from successful builds of another project Jenkins 与 Jenkinsfile 管道 - 远程触发构建 - Jenkins with Jenkinsfile Pipeline - Trigger Builds Remotely JenkinsFile:如何在运行时从脚本设置 env.variable? - JenkinsFile: How to set env.variable at runtime from a script? 如何使用Groovy Env。 Jenkins中的变量通过Jenkins管道中的bat命令传递 - How to use groovy env. variable in Jenkins to pass through bat command in Jenkins pipeline 如何在 Jenkinsfile 中配置要由 Jenkins 中的 Rails 应用程序的测试套件使用的数据库? - How to configure, in a Jenkinsfile, the database to be used by the test suite of a Rails app in Jenkins? Jenkins:来自 Jenkinsfile 的管道中的 env 为空 - Jenkins: env in pipeline from Jenkinsfile is null
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM