title: Jenkins: Trigger another job with branch name
body: <p>I am using Jenkins Pipeline via declarative and I would like to trigger another job with branch name.</p>
  <p>For instance, I have two different pipeline(PipelineA -PipelineB) with stages <code>JobA</code> and <code>JobB</code>.</p>
  <p>One of the stage for <code>JobA</code> should trigger the <code>JobB</code> via paramater using <code>env.GIT_BRANCH</code>. What I mean, if we trigger the <code>JobA</code> via origin/develop, then it should trigger the 'JobB' and run the stages where it has origin/develop condition.</p>
  <p>Meanwhile, we also making some separate changes on <code>JobB</code> and it also has its own GIT_BRANCH expression.Thus I could not able to find a way to manage this separately without affecting <code>JobA</code>. To be clarify, when JobA trigger JobB with origin/stage parameter, due to latest changes on JobB is origin/development whereas GIT_BRANCH is origin/development, I can not able to run the stages which has stage condition.</p>
  <p>Here is my script.</p>
  <pre><code>    stage ('Job A') {
          steps {
              script {
                  echo &quot;Triggering job for branch ${env.GIT_BRANCH}&quot;
                  ret = build(job: &quot;selenium_tests&quot;, 
                                  parameters: [
                                      string(name: &quot;projectName&quot;, value: &quot;Project1&quot;),
                                      string(name: &quot;branchName&quot;, value: &quot;env.GIT_BRANCH&quot;)
                                  ],
                                  propagate: true,
                                  wait: true)
  
                  echo ret.result
                  currentBuild.result = ret.result
              }           
          }
      }
  </code></pre>
  <hr />
  <pre><code>parameters {    
      string(defaultValue: &quot;project1&quot;, description: 'Which project do you want to test?', name: 'projectName')
      string(defaultValue: &quot;origin/development&quot;, description: 'Environment for selenium tests', name:'branchName')
  }
  
  
      stage ('Job B') {
          when {
              beforeAgent true
              expression { params.projectName == 'Project1' }
              expression { params.branchName == &quot;origin/stage&quot;}
              expression{ return env.GIT_BRANCH == &quot;origin/stage&quot;}
          }
          steps {
              script {
                    //Do something
              }           
          }
      }
  </code></pre>