Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-43104

Declarative pipeline branch condition not working

    Details

    • Similar Issues:

      Description

      I am working with a simple pipeline, just to get familiar with the system.  My pipeline is defined in the attached Jenkinsfile.  I can't seem to get the "Deploy" stage to work.  I am using the simple "when { branch 'master' }".  However I keep getting: Stage 'Deploy' skipped due to when conditional

      NOTE: This is a single branch repo with only a master branch

      Jenkins Version: 2.51

      Pipeline Plugin Version: 2.5

       

      Running on AWS Linux image. I followed this setup guide: https://aws.amazon.com/getting-started/projects/setup-jenkins-build-server/

       

        Attachments

          Issue Links

            Activity

            Hide
            scm_issue_link SCM/JIRA link daemon added a comment -

            Code changed in jenkins
            User: Andrew Bayer
            Path:
            content/doc/book/pipeline/syntax.adoc
            http://jenkins-ci.org/commit/jenkins.io/37472aedc9de44ca1f3cbe98c48becfefe8f706f
            Log:
            JENKINS-43104 Clarify that when->branch only works on multibranch

            Show
            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Andrew Bayer Path: content/doc/book/pipeline/syntax.adoc http://jenkins-ci.org/commit/jenkins.io/37472aedc9de44ca1f3cbe98c48becfefe8f706f Log: JENKINS-43104 Clarify that when->branch only works on multibranch
            Hide
            scm_issue_link SCM/JIRA link daemon added a comment -

            Code changed in jenkins
            User: R. Tyler Croy
            Path:
            content/doc/book/pipeline/syntax.adoc
            http://jenkins-ci.org/commit/jenkins.io/69263ee53b6f54e1d31485149be76fe08388a212
            Log:
            Merge pull request #982 from abayer/when-branch-only-for-multibranch

            JENKINS-43104 Clarify that when->branch only works on multibranch

            Compare: https://github.com/jenkins-infra/jenkins.io/compare/2822a194249e...69263ee53b6f

            Show
            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: R. Tyler Croy Path: content/doc/book/pipeline/syntax.adoc http://jenkins-ci.org/commit/jenkins.io/69263ee53b6f54e1d31485149be76fe08388a212 Log: Merge pull request #982 from abayer/when-branch-only-for-multibranch JENKINS-43104 Clarify that when->branch only works on multibranch Compare: https://github.com/jenkins-infra/jenkins.io/compare/2822a194249e...69263ee53b6f
            Hide
            miyajan Miyata Jumpei added a comment -

            FYI, trim() is required for the workaround in my case.

            when {
              expression {
                return sh(script: "git rev-parse --abbrev-ref HEAD", returnStdout: true).trim() == "master"
              }
            }
            
            Show
            miyajan Miyata Jumpei added a comment - FYI, trim() is required for the workaround in my case. when {   expression {     return sh(script: "git rev-parse --abbrev-ref HEAD" , returnStdout: true ).trim() == "master"   } }
            Hide
            onionhead0708 Raymond Chiu added a comment -

            Another workaround is to use:

            when {
              expression {
                return env.GIT_BRANCH == "origin/master"
              }
            } 

             

            Show
            onionhead0708 Raymond Chiu added a comment - Another workaround is to use: when { expression { return env.GIT_BRANCH == "origin/master" } }  
            Hide
            bitwiseman Liam Newman added a comment -

            Bulk closing resolved issues.

            Show
            bitwiseman Liam Newman added a comment - Bulk closing resolved issues.

              People

              • Assignee:
                abayer Andrew Bayer
                Reporter:
                d_smith Derek Smith
              • Votes:
                3 Vote for this issue
                Watchers:
                7 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: