[JIRA] (JENKINS-54047) All boolean parameters get set to true when used to set env vars.

1 view
Skip to first unread message

akdor1154@gmail.com (JIRA)

unread,
Oct 12, 2018, 7:20:02 AM10/12/18
to jenkinsc...@googlegroups.com
Jarrad Whitaker created an issue
 
Jenkins / Bug JENKINS-54047
All boolean parameters get set to true when used to set env vars.
Issue Type: Bug Bug
Assignee: Unassigned
Components: pipeline
Created: 2018-10-12 11:19
Environment: Jenkins LTS
Priority: Minor Minor
Reporter: Jarrad Whitaker

Using boolean parameters to set environment variables doesn't work for some crazy reason.

pipeline {
    agent none
    options {
        ansiColor('xterm')
        skipDefaultCheckout()
        durabilityHint('PERFORMANCE_OPTIMIZED')
    }
    parameters {
        booleanParam(
            name: 'lazyBuild',
            defaultValue: true,
            description: 'Skip build'
        )
    }
    stages {
        stage('WTF') {
            agent {
                label 'master'
            }
            environment {
                IS_LAZY = "${(params.lazyBuild) ? 't' : 'f'}"
                IS_NOT_LAZY = "${(!params.lazyBuild) ? 't' : 'f'}"
            }

            steps {
                sh 'echo IS_LAZY: $IS_LAZY'
                sh 'echo IS_NOT_LAZY: $IS_NOT_LAZY'
            }
        }
    }
}

Output:

[00-build] Running shell script
+ echo IS_LAZY: t
IS_LAZY: t
[Pipeline] sh
[00-build] Running shell script
+ echo IS_NOT_LAZY: t
IS_NOT_LAZY: t
Add Comment Add Comment
 
This message was sent by Atlassian Jira (v7.11.2#711002-sha1:fdc329d)

dnusbaum@cloudbees.com (JIRA)

unread,
Oct 12, 2018, 5:41:02 PM10/12/18
to jenkinsc...@googlegroups.com
Devin Nusbaum updated an issue
Change By: Devin Nusbaum
Component/s: pipeline-model-definition-plugin
Component/s: pipeline

dnusbaum@cloudbees.com (JIRA)

unread,
Oct 12, 2018, 5:41:02 PM10/12/18
to jenkinsc...@googlegroups.com
Devin Nusbaum commented on Bug JENKINS-54047
 
Re: All boolean parameters get set to true when used to set env vars.

I'm not quite sure what's going on here, but I was able to reproduce it. Looks like someone in JENKINS-47881 also mentioned a similar issues using the ternary operator for an environment variable. CC @abayer, are we all missing something obvious here?

pipeline {
    agent any
    parameters {
      booleanParam defaultValue: true, description: '', name: 'p1'
    }
    environment {
        NOT_P1 = "${(!params.p1) ? 'true' : 'false'}"
    }
    stages {
        stage('JENKINS-54047') {
            steps {
                // If p1 == true, then this prints "expecting false, got true"
                // If p1 == false, then this prints "expecting true, got false"
                echo "expecting ${!p1}, got ${NOT_P1}"
            }
        }
    }
} 

dnusbaum@cloudbees.com (JIRA)

unread,
Oct 12, 2018, 5:41:02 PM10/12/18
to jenkinsc...@googlegroups.com
Devin Nusbaum edited a comment on Bug JENKINS-54047
I'm not quite sure what's going on here, but I was able to reproduce it. Looks like someone in JENKINS-47881 also mentioned a similar issues using the ternary operator for an environment variable. CC @ [~ abayer ] , are we all missing something obvious here?
{code:java}

pipeline {
    agent any
    parameters {
      booleanParam defaultValue: true, description: '', name: 'p1'
    }
    environment {
        NOT_P1 = "${(!params.p1) ? 'true' : 'false'}"
    }
    stages {
        stage('JENKINS-54047') {
            steps {
                // If p1 == true, then this prints "expecting false, got true"
                // If p1 == false, then this prints "expecting true, got false"
                echo "expecting ${!p1}, got ${NOT_P1}"
            }
        }
    }
} {code}

dnusbaum@cloudbees.com (JIRA)

unread,
Oct 12, 2018, 5:41:02 PM10/12/18
to jenkinsc...@googlegroups.com

andrew.bayer@gmail.com (JIRA)

unread,
Oct 15, 2018, 7:14:02 AM10/15/18
to jenkinsc...@googlegroups.com
Andrew Bayer commented on Bug JENKINS-54047
 
Re: All boolean parameters get set to true when used to set env vars.

The JENKINS-47881 thing is a red herring - the actual problem here is that NotExpression isn't being handled properly in the environment value resolution - it's a descendant of BooleanExpression, but I wasn't distinguishing them, so !foo would end up being just foo. D'oh. PR incoming.

andrew.bayer@gmail.com (JIRA)

unread,
Oct 15, 2018, 7:16:01 AM10/15/18
to jenkinsc...@googlegroups.com
Andrew Bayer started work on Bug JENKINS-54047
 
Change By: Andrew Bayer
Status: Open In Progress

andrew.bayer@gmail.com (JIRA)

unread,
Oct 15, 2018, 7:16:01 AM10/15/18
to jenkinsc...@googlegroups.com

andrew.bayer@gmail.com (JIRA)

unread,
Oct 15, 2018, 7:16:02 AM10/15/18
to jenkinsc...@googlegroups.com

andrew.bayer@gmail.com (JIRA)

unread,
Oct 15, 2018, 7:17:02 AM10/15/18
to jenkinsc...@googlegroups.com

akdor1154@gmail.com (JIRA)

unread,
Oct 16, 2018, 9:02:01 PM10/16/18
to jenkinsc...@googlegroups.com

Thanks for quickly looking at this.
From an unfamiliar dev's point of view, it's a bit eyebrow raising that this sort of error-prone transformation is necessary.. isn't the point of using a DSL based on groovy that you can rely on groovy for basic stuff like this?

andrew.bayer@gmail.com (JIRA)

unread,
Oct 23, 2018, 4:01:02 AM10/23/18
to jenkinsc...@googlegroups.com
 

This'll be in the upcoming 1.3.3 release.

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

andrew.bayer@gmail.com (JIRA)

unread,
Oct 23, 2018, 4:04:03 AM10/23/18
to jenkinsc...@googlegroups.com
Andrew Bayer commented on Bug JENKINS-54047
 
Re: All boolean parameters get set to true when used to set env vars.

Jarrad Whitaker Yeah, it's a bit annoying - complicated DSLs like this are hairier than I'd like them to be, but we actually see a lot fewer bugs like this show up than I would have expected.

bitwiseman@gmail.com (JIRA)

unread,
Oct 22, 2019, 11:24:23 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