2016-06-07 117 views
4

將不勝感激一個體面的完整代碼示例如何將參數(參數化版本)從JobAJobB詹金斯管道插件?Jenkins管道插件傳遞建立作業參數之間的作業開始在管道

我使用的腳本像下面,不能從文檔圖如何從JobA訪問參數,比如說一個構建步驟shell腳本在JobB

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 

上面給出了一個錯誤:

groovy.lang.MissingPropertyException: No such property: CVS_TAG for class: groovy.lang.Binding

並且不能在JobB的構建步驟shell腳本中訪問$CVS_TAG

感謝

按照您的回答,我也嘗試過這種不成功:

構建工作: '職吧',參數:[[$類: 'StringParameterValue',名稱: 'test_param',值:'工作']]

env.test_param = test_param

回聲$ {test_param}

的誤差總是:

groovy.lang.MissingPropertyException:沒有這樣的屬性:test_param類:在groovy.lang.Binding.getVariable groovy.lang.Binding(Binding.java:63)

+0

這個答案可能給你一個線索:https://stackoverflow.com/questions/37079913/pass-jenkins-build-parameters-to-pipeline-nodes/37090331#37090331 – izzekil

+0

你有沒有啓用「這個項目是pa rameterized「在Build JobB中?還要注意,你可以用這種方式訪問​​參數$ {CVS_TAG}。 – mrkernelpanic

+0

看看答案http://stackoverflow.com/questions/37675194/how-to-obtain-the-folder-where-the-pipeline-jenkinsfile-is-checked-out-jenkins – CSchulz

回答

3

上游職吧:

//do something 
env.CVS_TAG = 'test' 
build job: 'JobB' 

下游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 
} 
+0

詹金斯什麼版本,你得到這個工作? – raffian

+0

@raffian這個工作爲2.7和2.12版本 – anton

相關問題