[JIRA] (JENKINS-50622) when condition not correctly discovering branch

1 view
Skip to first unread message

domi@fortysix.ch (JIRA)

unread,
Apr 6, 2018, 5:32:02 AM4/6/18
to jenkinsc...@googlegroups.com
Dominik Bartholdi updated an issue
 
Jenkins / Bug JENKINS-50622
when condition not correctly discovering branch
Change By: Dominik Bartholdi
I created a new pipeline job and defined "Pipeline script from SCM" using Git:
* repo Url: g...@bitbucket.org:yooture/xxx.git
* branch specifier: */master
* Repository browser: (auto)
* Additional Behaviours: none
* Script Path: Jenkinsfile
* Lightweight checkout: on

In have the following
simele   simple pipeline:

 
{code:java}
pipeline {
  agent { label 'lxc-fedora25' }

  tools {
    maven 'MVN_352'
    jdk "Oracle JDK 1.8 (latest)"
  }

  stages { 
    stage('build Snapshot') {
      when { not { branch 'master' } }      
      steps {
         sh 'mvn clean install -Dmaven.test.failure.ignore'
      }
    }
    stage('Build Release') {
      when { branch 'master' }
      steps {    
          sh "mvn clean deploy"
      }
    }      
  }
}{code}
 

even though the branch specifier is specified as "*/master", "build Snapshot" stage is always executed :(

 

 
Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v7.3.0#73011-sha1:3c73d0e)
Atlassian logo

domi@fortysix.ch (JIRA)

unread,
Apr 6, 2018, 5:32:03 AM4/6/18
to jenkinsc...@googlegroups.com
Dominik Bartholdi created an issue
Issue Type: Bug Bug
Assignee: Andrew Bayer
Components: pipeline-model-definition-plugin
Created: 2018-04-06 09:31
Environment: Pipeline Model Definition Plugin: 1.2.2
Priority: Critical Critical
Reporter: Dominik Bartholdi

I created a new pipeline job and defined "Pipeline script from SCM" using Git:

  • repo Url: g...@bitbucket.org:yooture/xxx.git
  • branch specifier: */master
  • Repository browser: (auto)
  • Additional Behaviours: none
  • Script Path: Jenkinsfile
  • Lightweight checkout: on

In have the following simele pipeline:

 

pipeline {
  agent { label 'lxc-fedora25' }

  tools {
    maven 'MVN_352'
    jdk "Oracle JDK 1.8 (latest)"
  }

  stages { 
    stage('build Snapshot') {
      when { not { branch 'master' } }      
      steps {
         sh 'mvn clean install -Dmaven.test.failure.ignore'
      }
    }
    stage('Build Release') {
      when { branch 'master' }
      steps {    
          sh "mvn clean deploy"
      }
    }      
  }
}

 

even though the branch specifier is specified as "*/master", "build Snapshot" stage is always executed

 

 

domi@fortysix.ch (JIRA)

unread,
Apr 6, 2018, 5:47:02 AM4/6/18
to jenkinsc...@googlegroups.com
Dominik Bartholdi commented on Bug JENKINS-50622
 
Re: when condition not correctly discovering branch

btw. this stage:

    stage('prepare yoo') {
      steps {
        echo "on ${env.BRANCH_NAME}"
      }
    }

does print 'on null' - I guess this is the root problem, but I have no idea why this is the case...

andrew.bayer@gmail.com (JIRA)

unread,
Apr 12, 2018, 11:39:01 AM4/12/18
to jenkinsc...@googlegroups.com
Andrew Bayer resolved as Not A Defect
 

Yeah, the branch when condition actually only works for multibranch - each SCM may have different environment variables for representing the branch, so we can't know what variable to check unless you're using multibranch, in which case we've got the env.BRANCH variable to look at.

Change By: Andrew Bayer
Status: Open Resolved
Resolution: Not A Defect

domi@fortysix.ch (JIRA)

unread,
Apr 12, 2018, 3:48:02 PM4/12/18
to jenkinsc...@googlegroups.com
 
Re: when condition not correctly discovering branch

OK, my bad - thanks for the explanation!

...but should this not be aligned somehow? I think it just does not make much sense to have different names in different job types...

andrew.bayer@gmail.com (JIRA)

unread,
Apr 12, 2018, 4:17:02 PM4/12/18
to jenkinsc...@googlegroups.com

Dominik Bartholdi - Oh, definitely...which is why it is standardized with multibranch and env.BRANCH. Note that if you're using git, env.BRANCH_NAME will also still be available in a multibranch job, so you can use, say,

when {
  expression { return env.BRANCH_NAME == "master" }
}

whether you're in a "Pipeline script from SCM" or multibranch.

bitwiseman@gmail.com (JIRA)

unread,
Oct 22, 2019, 11:24:21 PM10/22/19
to jenkinsc...@googlegroups.com
Liam Newman closed an issue as Not A Defect
 

Bulk closing resolved issues.

Change By: Liam Newman
Status: Resolved Closed
This message was sent by Atlassian Jira (v7.13.6#713006-sha1:cc4451f)
Atlassian logo
Reply all
Reply to author
Forward
0 new messages