[JIRA] (JENKINS-50815) beside GIT_BRANCH also expose it as BRANCH

2 views
Skip to first unread message

domi@fortysix.ch (JIRA)

unread,
Apr 16, 2018, 4:40:02 AM4/16/18
to jenkinsc...@googlegroups.com
Dominik Bartholdi created an issue
 
Jenkins / Improvement JENKINS-50815
beside GIT_BRANCH also expose it as BRANCH
Issue Type: Improvement Improvement
Assignee: Mark Waite
Components: git-plugin
Created: 2018-04-16 08:39
Priority: Minor Minor
Reporter: Dominik Bartholdi

jenkins declarative pipeline has a nice  condition to check for branch names:

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

unfortunate, it only checks for the branch name in `env.BRANCH`. Sure, I can use something like this:

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

but that's not as nice as the former...

The other solution for this would be, the pipeline-model-definition-plugin would check for multiple variables (BRANCH_NAME, BRANCH, GIT_BRANCH) and maybe throw an error in case they define different values (except for null).

This does not sound like a big issue, but for sure it will make a lot of things easier to understand, e.g. why would the condition behave different in a multibranch job then in a normal job?

please also see JENKINS-50622 

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

mark.earl.waite@gmail.com (JIRA)

unread,
Apr 16, 2018, 9:13:02 AM4/16/18
to jenkinsc...@googlegroups.com
Mark Waite assigned an issue to Unassigned
Change By: Mark Waite
Assignee: Mark Waite

mark.earl.waite@gmail.com (JIRA)

unread,
Apr 16, 2018, 9:13:02 AM4/16/18
to jenkinsc...@googlegroups.com
Mark Waite updated an issue
Change By: Mark Waite
Component/s: pipeline-model-definition-plugin
Component/s: git-plugin

mark.earl.waite@gmail.com (JIRA)

unread,
Apr 16, 2018, 9:17:02 AM4/16/18
to jenkinsc...@googlegroups.com
Mark Waite commented on Improvement JENKINS-50815
 
Re: beside GIT_BRANCH also expose it as BRANCH

Dominik Bartholdi the multi-branch Pipeline already works as you describe, at least according to JENKINS-50622. If Pipeline (without multi-branch) needs to work that way, it is a change to another plugin, not the git plugin. I assigned this to the model definition plugin in hopes that is the correct location.

I'm unwilling to add the "BRANCH" environment variable to the git plugin because that risks confusion for other plugins (like Pipeline) which operate with that environment variable. I don't want to manage precedence rules (when does the git plugin assignment of BRANCH override the Pipeline assignment of branch). The git plugin records the branch name in GIT_BRANCH. Other plugins may use different environment variable names for branches.

domi@fortysix.ch (JIRA)

unread,
Apr 16, 2018, 9:21:02 AM4/16/18
to jenkinsc...@googlegroups.com

Mark Waite the fact that I can not run the pipeline as shown in JENKINS-50622 without multi-branch shows that it does not the way I described it. I would expect to be able to run the same pipeline in a normal pipeline job and in multi-branch, but thats not working.

andrew.bayer@gmail.com (JIRA)

unread,
Apr 16, 2018, 2:35:02 PM4/16/18
to jenkinsc...@googlegroups.com

It's worth considering adding some backup heuristics in Declarative - i.e., if env.BRANCH is undefined, check env.GIT_BRANCH, etc... Will need to think about this.

andrew.bayer@gmail.com (JIRA)

unread,
Apr 17, 2018, 4:42:02 PM4/17/18
to jenkinsc...@googlegroups.com
Andrew Bayer started work on Improvement JENKINS-50815
 
Change By: Andrew Bayer
Status: Open In Progress

andrew.bayer@gmail.com (JIRA)

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

andrew.bayer@gmail.com (JIRA)

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

andrew.bayer@gmail.com (JIRA)

unread,
Apr 17, 2018, 4:45:02 PM4/17/18
to jenkinsc...@googlegroups.com
 
Re: beside GIT_BRANCH also expose it as BRANCH

PR up at https://github.com/jenkinsci/pipeline-model-definition-plugin/pull/265 adding fallback to GIT_LOCAL_BRANCH (which doesn't have the remote on it, unlike GIT_BRANCH) if BRANCH_NAME is null.

scm_issue_link@java.net (JIRA)

unread,
Apr 24, 2018, 3:40:02 PM4/24/18
to jenkinsc...@googlegroups.com

Code changed in jenkins
User: Andrew Bayer
Path:
pipeline-model-definition/src/main/resources/org/jenkinsci/plugins/pipeline/modeldefinition/when/impl/BranchConditionalScript.groovy
pipeline-model-definition/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/BasicModelDefTest.java
pipeline-model-definition/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/WhenStageTest.java
pipeline-model-definition/src/test/resources/whenBranchNotMultibranch.groovy
pom.xml
http://jenkins-ci.org/commit/pipeline-model-definition-plugin/7fb4f69e3cf4fb9bfcd5addd10f96febd1d0e4fc
Log:
[FIXED JENKINS-50815] Fallback to GIT_LOCAL_BRANCH for when branch

If we're not on multibranch (meaning BRANCH_NAME is null), fallback to
GIT_LOCAL_BRANCH for when branch condition. We can theoretically add
other SCMs here too if needed. We're using GIT_LOCAL_BRANCH because it
most closely matches BRANCH_NAME - i.e., GIT_BRANCH includes the
remote, GIT_LOCAL_BRANCH does not.

andrew.bayer@gmail.com (JIRA)

unread,
Apr 24, 2018, 3:41:01 PM4/24/18
to jenkinsc...@googlegroups.com
 

Merged, will be in 1.2.10.

Change By: Andrew Bayer
Status: In Review Resolved
Resolution: Fixed

bitwiseman@gmail.com (JIRA)

unread,
Oct 22, 2019, 11:25:20 PM10/22/19
to jenkinsc...@googlegroups.com
Liam Newman closed an issue as Fixed
 

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