Jenkins管道插件传递构建在管道中开始的作业之间的作业参数 [英] Jenkins Pipeline Plugin pass build Job parameters between jobs started in a pipeline
问题描述
感谢一个体面的完整代码示例,告诉我们如何从 JobA
到 JobB
在詹金斯管道插件?
我使用下面的脚本,并且无法从文档中找出如何从 JobA
中访问参数在 JobB
中创建步骤shell脚本:
编译作业:'JobA ',参数:[[$ class:'StringParameterValue',name:'CVS_TAG',value:'test']]
构建作业:'JobB',参数:[[$ class:'StringParameterValue ',name:'CVS_TAG',value:'test']]
echo env.CVS_TAG
$
$ b
groovy.lang.MissingPropertyException:没有这样的属性:类CVS_TAG:groovy.lang .Binding 在构建步骤shell脚本中无法访问
$ CVS_TAG
在JobB
。
谢谢
构建作业:'JobA',参数:[[$ class:'StringParameterValue',name:' test_param',value:'working']]
env.test_param = test_param
echo $ {test_param}
错误总是:
groovy.lang.MissingPropertyException:没有这样的属性:test_param for class:groovy .lang.Binding at groovy.lang.Binding.getVariable(Binding.java:63)
解决方案上游JobA:
//做某事
env.CVS_TAG ='test'
建立作业:'JobB'
下游工作B:
import hudson.EnvVars
import org.jenkinsci.plugins.workflow.cps.EnvActionImpl
import hudson.model.Cause
def upstreamEnv = new EnvVars()
节点{
//如果当前构建由另一个运行,我们开始获取变量
def upstreamCause = currentBuild.rawBuild.getCause(Cause $ UpstreamCause)
if(upstreamCause){
def upstreamJobName = upstreamCause.properties.upstre amProject
def upstream upstreamBuild = Jenkins.instance
.getItemByFullName(upstreamJobName)
.getLastBuild()
upstreamEnv = upstreamBuild.getAction(EnvActionImpl).getEnvironment()
}
def CVS_TAG = upstreamEnv.CVS_TAG
echo CVS_TAG
}
Would be grateful for a decent full code example of how to pass parameters (parameterized build) from
JobA
toJobB
in Jenkins Pipeline plugin?I am using a script like below and can not figure from the docs how to access parameters from
JobA
in say a build step shell script inJobB
:build job: 'JobA', parameters: [[$class: 'StringParameterValue', name: 'CVS_TAG', value: 'test']] build job: 'JobB', parameters: [[$class: 'StringParameterValue', name: 'CVS_TAG', value: 'test']] echo env.CVS_TAG
Above gives an error:
groovy.lang.MissingPropertyException: No such property: CVS_TAG for class: groovy.lang.Binding
And can not access
$CVS_TAG
in a build step shell script inJobB
.Thanks
Per you responses I have also tried this unsuccessfully:
build job: 'JobA', parameters: [[$class: 'StringParameterValue', name: 'test_param', value: 'working']]
env.test_param=test_param
echo ${test_param}
The error is always:
groovy.lang.MissingPropertyException: No such property: test_param for class: groovy.lang.Binding at groovy.lang.Binding.getVariable(Binding.java:63)
解决方案Upstream JobA:
//do something env.CVS_TAG = 'test' build job: 'JobB'
Downstream JobB:
import hudson.EnvVars import org.jenkinsci.plugins.workflow.cps.EnvActionImpl import hudson.model.Cause def upstreamEnv = new EnvVars() node { //if the current build is running by another we begin to getting variables def upstreamCause = currentBuild.rawBuild.getCause(Cause$UpstreamCause) if (upstreamCause) { def upstreamJobName = upstreamCause.properties.upstreamProject def upstreamBuild = Jenkins.instance .getItemByFullName(upstreamJobName) .getLastBuild() upstreamEnv = upstreamBuild.getAction(EnvActionImpl).getEnvironment() } def CVS_TAG = upstreamEnv.CVS_TAG echo CVS_TAG }
这篇关于Jenkins管道插件传递构建在管道中开始的作业之间的作业参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!