<p>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 <code>$GIT_BRANCH</code> is a variable.</p>

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

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

<p>Note that <code>/</code> in the branchname must be escaped.</p>

<p>So I recommend to rewrite your job with a Jenkinsfile :-)</p>

CC BY-SA 4.0
2021-06-15T15:00:24.667Z
Note it's sometimes best to add a downstream job not as a 'post' stage e.g. success { script { build {...
JohnZaj
CC BY-SA 4.0
2020-04-30T12:24:31.207Z
2020-04-30T12:24:31.207Z
simonz
<p>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.</p>

CC BY-SA 4.0
2020-04-23T00:23:05.353Z
2020-04-23T00:23:05.353Z
minhluantran017
<p>I have an upstream freestyle job and a downstream pipeline job.</p>

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

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

<p>How to pass the branch name to the pipeline job dynamically?
<a href="https://i.sstatic.net/Yqby8.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Yqby8.png" alt="enter image description here"></a></p>

<jenkins><jenkins-pipeline>
Trigger downstream pipeline job for the branch via from upstream freestyle job
user21870
# Trigger downstream pipeline job for the branch via from upstream freestyle job

(Asked by: username_0 on 2020-04-22)

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](https://i.sstatic.net/Yqby8.png)](https://i.sstatic.net/Yqby8.png)

**Tags:** jenkins, jenkins-pipeline


---

## 2 answers

### Answer by username_1 on 2020-04-30. Score: 1

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

> **Comments:**
> **username_2**: Note it's sometimes best to add a downstream job not as a 'post' stage e.g. success { script { build {...  

---

### Answer by username_3 on 2020-04-23. Score: 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.


---

