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