简体   繁体   English

在同一 Jenkins 管道中的下一个新代理中,如何在上一个结束的代理中获取自定义环境变量(使用 AWS 代码提交 Jenkins 项目)

[英]At next new agent in the same Jenkins Pipeline, how to get customized environment variable in last ended agent (using AWS Code commit Jenkins project)

I deploy Jenkins on EKS, my pipeline is:我在 EKS 上部署 Jenkins,我的管道是:

pipeline {
    stage("build") {
        //start a agent "agent_label"
    }

    //Now, end that agent, for the reason of waiting for user input.

    stage("deploy") {
        //start the agent "agent_label"
    }
 
}

At the "build" stage, I get the git commit version, I want to use it in the "deploy" stage.在“构建”阶段,我得到了 git commit 版本,我想在“部署”阶段使用它。 Because the agent terminates, the environment variable in the "build" stage will be unavaliable.由于代理终止,“构建”阶段的环境变量将不可用。 So how to solve it?那么如何解决呢?

I have searched for it.我已经搜索过了。 It says I should use "Persistent Parameter".它说我应该使用“持久参数”。 But there isn't a "Persistent Parameter" configuration on the Jenkins project type of "AWS Code commit" that I use.但是在我使用的“AWS 代码提交”的 Jenkins 项目类型上没有“持久参数”配置。 I only see that configuration on on the Jenkins project type of "Pipeline".我只在“管道”的 Jenkins 项目类型上看到该配置。

Another way may be changing the Jenkins BUILD_NUMBER to git commit version.另一种方法可能是将 Jenkins BUILD_NUMBER 更改为 git commit 版本。 But I do not know how to do that.但我不知道该怎么做。

Thanks in advance!提前致谢!

Actually, the parameter can persistent even if the agent is shut down and restart.实际上,即使代理关闭并重新启动,该参数也可以保持不变。 For example, if I set a varable in "build" stage, I can still get it at the "deploy" stage.例如,如果我在“构建”阶段设置了一个变量,我仍然可以在“部署”阶段获得它。

Also, for changing the Jenkins BUILD_NUMBER environment variable, you can use Build name setter plugin for Jenkins .此外,为了更改 Jenkins BUILD_NUMBER 环境变量,您可以使用Build name setter plugin for Jenkins

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM