1

I have an upstream freestyle job and a downstream pipeline job.

The freestyle job is triggered via a gitHub webhook to run whenever code is pushed to gitHub branch.

The freestyle job should capture the branch name and pass to the pipeline job and should trigger the build for that particular branch.

How to pass the branch name to the pipeline job dynamically? enter image description here

1

The "Add Parameters" can help you. You should set up your downstream pipeline with "GIT_BRANCH" parameter to build with that branch, and transfer it from this upstream job.

| improve this answer | |
0

Can't tell you why this does not work, I'm not using the Jenkins UI for build configuration anymore. I guess the Jenkins UI is blocking you because it does not recognize tha $GIT_BRANCH is a variable.

We do exactly what you are trying with a script-step in the pipeline, and that works:

stage('Trigger downstream job') {
   steps {
      script {
         build(job: 'SomeJob/' + env.GIT_BRANCH.replaceAll('/', '%2F'),
               parameters: [...],
               propagate: true,
               wait: true)
      }
   }
}

Note that / in the branchname must be escaped.

So I recommend to rewrite your job with a Jenkinsfile :-)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.