branch specific jenkins pipeline trigger I am trying to trigger a jenkins pipeline job only when a pull request has been approved &amp; merged to a specific github branch in our CI/CD implementation.
currently whenever i merge a PR to release, jenkins job that is created to get triggered when PR is merged to master is also getting triggered, while I only want release jenkins job to be triggered.
strangely echo env.GIT_BRANCH cmd shows branch name as MASTER in master job, parallelly release job shows branch as RELEASE, when i only merged PR to release.
Things tried:

Branches to build feature in Jenkins
when condition in Jenkinsfile (its acting weird, both staging and production jobs are getting triggered when one branch is targetted)

Environment:
Jenkins ver. 2.176.3, Docker,Generic webhook trigger for Jenkins
I'm convinced that when condition will work, but for me it isn't, following is my partial when condition in Jenkinsfile:
stage(&quot;Step 1: Build Docker&quot;){}
stage(&quot;Step 2: Push to DockerHub&quot;){}
stage(&quot;Step 3: Production Deployment&quot;){
            when {
                expression { return params.current_status == &quot;closed&quot; &amp;&amp; params.merged == true &amp;&amp; env.GIT_BRANCH == &quot;origin/master&quot; }
            }
            steps{
                -----
                sh 'kubectl apply -f **.yaml'
            }
}

In my jenkinsfile I'm writing logic to deploy my docker images to kubernetes cluster, so all that i  am looking for is to accurately trigger the job based on the branch.
Any suggestions on how to get it to work, what am i missing here?
Do you have 2 different jenkins jobs configured for master and release branches? Since github webhook event is sent to Jenkins irrespective of branch, both your jenkins jobs may be getting triggered by this github webhook event. And since both jobs are configured with separate branches, they may be checking out those branches during jenkins job execution which is why you may be seeing respective branches being printed in both jenkins jobs.
Checkout jenkins multibranch pipeline if you haven't already so you don't have to maintain multiple jenkins jobs for branches.
Now coming back to your Jenkinsfile code, you can try following:

Replace env.GIT_BRANCH with env.BRANCH_NAME

Use allOf inside when condition instead of &amp;&amp;  -
stage(&quot;Step 3: Production Deployment&quot;){
    when {
        allOf {
            expression { env.BRANCH_NAME == &quot;origin/master&quot; }
            expression { params.merged == true }
            expression { params.current_status == &quot;closed&quot; }
        }
    }
    steps{
        -----
        sh 'kubectl apply -f **.yaml'
    } 
}



Note that github webhook will trigger the jenkins job for every branch push or PR merge event (irrespective of branch), so your jenkins job would have to handle multi-branch scenarios like explained in this official doc example.