4

Would be grateful for a decent full code example of how to pass parameters (parameterized build) from JobA to JobB 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 in 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 

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 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)

5
  • This answer might give you a clue: stackoverflow.com/questions/37079913/… Commented Jun 7, 2016 at 9:59
  • Did you enable "This project is parameterized" in Build JobB? Also note that you can access the Parameters in this way ${CVS_TAG}. Commented Jun 7, 2016 at 13:11
  • Have a look into the answer stackoverflow.com/questions/37675194/… Commented Jun 7, 2016 at 15:33
  • Thanks for the response but I am not able to get this working? Any working script examples using build job? Commented Jun 7, 2016 at 19:35
  • Any ideas what I am doing wrong? This seems like the most important feature when using a pipeline and there is very little in the way of doc's / example of how to use it? Commented Jun 8, 2016 at 5:29

1 Answer 1

3

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 } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.