[JIRA] (JENKINS-50418) when {branch} stage conditional regression

0 views
Skip to first unread message

ericdnelson@gmail.com (JIRA)

unread,
Mar 26, 2018, 11:01:03 PM3/26/18
to jenkinsc...@googlegroups.com
Eric Nelson created an issue
 
Jenkins / Bug JENKINS-50418
when {branch} stage conditional regression
Issue Type: Bug Bug
Assignee: Unassigned
Components: pipeline
Created: 2018-03-27 03:00
Environment: Jenkins 2.112
Pipeline: API 2.26
Pipeline: Model API 1.2.7
Priority: Minor Minor
Reporter: Eric Nelson

The when branch conditional seems to still be broken. Similar to JENKINS-41012. In this case we are using GitHub with webhooks to trigger a build.  Following the good test code in 41012 I tested with the following. 

Results - I get echo expression and echo env, but branch is always skipped. 

Test pipeline code stage is:

stages {
stage('test condition: expression') {
when {
expression {
return env.GIT_BRANCH == "origin/master"
}
}
steps {
sh 'echo "expression"'
}
}

stage('test when: env') {
when {
environment name: "GIT_BRANCH", value: "origin/master"
}
steps {
sh 'echo "env"'
}
}

stage('test when: branch') {
when {
branch "master"
}
steps {
sh 'echo "branch"'
}
}
}
Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v7.3.0#73011-sha1:3c73d0e)
Atlassian logo

ericdnelson@gmail.com (JIRA)

unread,
Mar 26, 2018, 11:02:02 PM3/26/18
to jenkinsc...@googlegroups.com
Eric Nelson updated an issue
Change By: Eric Nelson
The when branch conditional seems to still be broken. Similar to - JENKINS-41012 - . In this case we are using GitHub with webhooks to trigger a build.  Following the good test code in 41012 I tested with the following. 


Results - I get echo expression and echo env, but branch is always skipped. 

Test pipeline code stage is:
{code:java}

stages {
stage('test condition: expression') {
when {
expression {
return env.GIT_BRANCH == "origin/master"
}
}
steps {
sh 'echo "expression"'
}
}

stage('test when: env') {
when {
environment name: "GIT_BRANCH", value: "origin/master"
}
steps {
sh 'echo "env"'
}
}

stage('test when: branch') {
when {
branch " origin/ master"
}
steps {
sh 'echo "branch"'
}
}
}
{code}

andrew.bayer@gmail.com (JIRA)

unread,
Mar 27, 2018, 2:32:02 PM3/27/18
to jenkinsc...@googlegroups.com
Andrew Bayer updated an issue
Change By: Andrew Bayer
Component/s: pipeline-model-definition-plugin
Component/s: pipeline

andrew.bayer@gmail.com (JIRA)

unread,
Mar 27, 2018, 2:33:02 PM3/27/18
to jenkinsc...@googlegroups.com

andrew.bayer@gmail.com (JIRA)

unread,
Mar 27, 2018, 2:35:03 PM3/27/18
to jenkinsc...@googlegroups.com
Andrew Bayer commented on Bug JENKINS-50418
 
Re: when {branch} stage conditional regression

The branch conditional is checking against the more generalized BRANCH_NAME environment variable, which is only set for multibranch Pipelines. Is this on a multibranch Pipeline or just a standalone Pipeline job?

ericdnelson@gmail.com (JIRA)

unread,
Mar 27, 2018, 3:54:01 PM3/27/18
to jenkinsc...@googlegroups.com

This one is a stand alone pipeline job. Which explains why when I checked BRANCH_NAME it also did nothing. 

Is there a recommendation for branch checking in stand alone pipeline jobs? 

andrew.bayer@gmail.com (JIRA)

unread,
Mar 27, 2018, 4:00:02 PM3/27/18
to jenkinsc...@googlegroups.com

Probably environment name: "GIT_BRANCH", value: "origin/master" as you tried out above - there's no consistent env var for the branch across all SCMs except in the context of a multibranch Pipeline, so you do need check that Git-specific one.

andrew.bayer@gmail.com (JIRA)

unread,
Apr 3, 2018, 1:10:04 PM4/3/18
to jenkinsc...@googlegroups.com
Andrew Bayer resolved as Not A Defect
 
Change By: Andrew Bayer
Status: Open Resolved
Resolution: Not A Defect

bitwiseman@gmail.com (JIRA)

unread,
Oct 22, 2019, 11:25:55 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