4

I have project A and project B. I would like to pass parameters (like the BranchName and ArtifactoryID) from project A to project B. Both are multi-branch pipelines using a Declarative Script Jenkinsfile.

When I use the Snippet Generator it tells me the project "is not parameterized". When looking at the config of the multi-branch pipeline, I don't see a way to parameterize it. What am I missing? (see attached)

enter image description here

enter image description here

A google result shows this, but I'm not sure how it's supposed to pass params between multi-branch pipelines: https://issues.jenkins-ci.org/browse/JENKINS-32780

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Japster24
  • 1,486
  • 3
  • 21
  • 23

1 Answers1

5

I figured this out. I leveraged an answer from a comment here: Pipeline pass parameters to downstream jobs

For a detailed explanation using my example shown above, my Project A jenkinsfile would have the following before the stages:

  parameters
  {
    string(name: 'BRANCH_PASSED_OVER', defaultValue: '${env.BRANCH_NAME}', description: 'pass branch value')
    string(name: 'PERSON2', defaultValue: 'Mr Jenkins', description: 'Who should I say hello to?')
  }

...and the following for the build step phase

  stage('Build downstream')
  {
    steps
    {
    build job: 'BUILD/CMTest2/' + env.BRANCH_NAME.replaceAll("/", "%2F"), wait: false, parameters: [string(name: 'PERSON2', value: params.PERSON2), string(name: 'PASS_BRANCH_NAME', value: env.BRANCH_NAME)]
    }
  }

In Project B then in my jenkinsfile I could call the param like so:

  stage('Collect Info')
  {
    steps
    {
      echo "Hello ${params.PERSON2}"
      echo "PASS_BRANCH_NAME: ${params.PASS_BRANCH_NAME}"
    }
  }
Community
  • 1
  • 1
Japster24
  • 1,486
  • 3
  • 21
  • 23
  • 1
    are you calling the build via rest? I'm receiving either a 500 or 404 HTTP error when calling POST http://127.0.0.1:9000/job/projectname/job/branchname/buildWithParameters?PARAM_NAME=value – Learner Apr 19 '18 at 00:51