Jenkins管道插件传递构建在管道中开始的作业之间的作业参数

Jenkins管道插件传递构建在管道中开始的作业之间的作业参数

本文介绍了Jenkins管道插件传递构建在管道中开始的作业之间的作业参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

感谢一个体面的完整代码示例,告诉我们如何从 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

And can not access $CVS_TAG in a build step shell script in JobB.

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管道插件传递构建在管道中开始的作业之间的作业参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 04:59