简体   繁体   English

如何使作业dsl设置的环境变量在下游作业中可用?

[英]How to make environment variable set by job dsl avaiable in downstream jobs?

The job seeder creates a pipeline job and sets environment variable using job dsl as shown below, this pipeline job triggers another job(say job2) which in turn triggers another job(say job3). 作业播种器创建一个管道作业,并使用作业dsl设置环境变量,如下所示,该管道作业触发另一个作业(例如job2),而后者又触发另一个作业(例如job3)。 I want the environment variable set in seed job to be accessed in the triggered jobs. 我希望在触发的作业中访问种子作业中设置的环境变量。

pipelineJob("job1"){
  description("job1..")
  concurrentBuild(false)
  environmentVariables(
         globalEnv + [TEMP_ENV1               : 'true',
                      TEMP_ENV2               : 'true'
                     ]
   )
  definition {
      cps {
         script(
               """
job1script()
"""
         )
      }
   }
}

I want to access TEMP_ENV1 and TEMP_ENV2 in job3, but both are null in this job. 我想访问job3中的TEMP_ENV1和TEMP_ENV2,但在此作业中两者均为空。 i have a check in script which job3 executes it and it fails, eg if (env.TEMP_ENV1) { } 我有一个签入脚本,哪个job3执行了它,但失败了,例如if (env.TEMP_ENV1) { }

You should invoke the job using the build step ( https://jenkins.io/doc/pipeline/steps/pipeline-build-step/ ) and pass these along as parameters: 您应该使用构建步骤( https://jenkins.io/doc/pipeline/steps/pipeline-build-step/ )调用作业,并将它们作为参数传递:

build(
    job: "myjob2", 
    parameters: [
        string(name: 'TEMP_ENV1', defaultValue: TEMP_ENV1, description: 'Temp env var 1')
    ], 
    propagate: false
)

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

相关问题 如何在詹金斯中将参数作为环境变量从上游作业传递到下游作业? 无需对下游工作进行参数化 - How to pass parameter as environment variable from upstream job to downstream job in jenkins? without downstream jobs being parametrized 如何将环境变量传递给下游工作? - How to pass environment variable to downstream job? 在Jenkins中设置主作业的下游作业的内部版本号 - Set build number of downstream jobs from master job in Jenkins 如何阻止父作业,直到两个下游作业都完成 - How to block parent job until both the downstream jobs are completed 如果下游作业失败,如何使主詹金斯管道作业失败 - How to fail master Jenkins pipeline job if downstream jobs fails 在管道作业中,如何使用他们选择的参数构建自由式下游作业? - In pipeline job how to build freestyle downstream jobs with their choice parameters? 如何使用凭据绑定插件在Jenkins DSL中设置环境变量? - How to set an environment variable in Jenkins DSL using the Credentials Binding plugin? 如何使用Jenkins DSL为所有作业设置作业超时 - How can I set the job timeout for all jobs using the Jenkins DSL 如何将Python变量传递给管道中的下游作业 - How to pass Python variable to the downstream job in pipeline 我如何使一份工作与 Jenkins 中的一组工作相互排斥? - How do I make a job mutually exclusive with a set of jobs in Jenkins?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM