Details
-
Type:
Improvement
-
Status: Fixed but Unreleased (View Workflow)
-
Priority:
Critical
-
Resolution: Not A Defect
-
Component/s: pipeline-model-definition-plugin
-
Environment:Jenkins: 2.73.3
-
Similar Issues:
Description
Hi,
Currently there is no option to set an environment variable based on boolean value within the environment directive. I think it is crucial to implement support for something like this:
pipeline{ agent any environment { /*Option1*/ condition $params.some_bool_parameter{CC = "1"} /* Option2 variable will be set to "1" only if the boolean value is true */ CC = $params.some_bool_parameter : "1" /* This is currently supported */ CC = $params.some_non_bool_parameter } }
Attachments
Activity
Field | Original Value | New Value |
---|---|---|
Description |
Hi, Currently there is no option to set an environment variable based on boolean value within the environment directive. I think it is crucial to implement support for something like this: {{}}{{pipeline \{}} {{agent any}} {{environment \{}} {{ /* Option1 */}} {{ condition $params.some_bool_parameter\{}} {{ CC = "1"}} {{ }}} {{ /*Option2 variable will be set to "1" onlt if the boolean value if true*/}} {{ CC = $params.some_bool_parameter : "1"}} {{ }} {{ /* This is currently supported */}} {{ CC = $params.some_*non*_bool_parameter}} {{}}} |
Hi, Currently there is no option to set an environment variable based on boolean value within the environment directive. I think it is crucial to implement support for something like this: {{pipeline \{}} {{agent any}} {{environment \{}} {{ /* Option1 */}} {{ condition $params.some_bool_parameter\{}} {{ CC = "1"}} {{ }}} {{ /*Option2 variable will be set to "1" onlt if the boolean value if true*/}} {{ CC = $params.some_bool_parameter : "1"}} {{ }} {{ /* This is currently supported */}} {{ CC = $params.some_*non*_bool_parameter}} {{}}} |
Description |
Hi, Currently there is no option to set an environment variable based on boolean value within the environment directive. I think it is crucial to implement support for something like this: {{pipeline \{}} {{agent any}} {{environment \{}} {{ /* Option1 */}} {{ condition $params.some_bool_parameter\{}} {{ CC = "1"}} {{ }}} {{ /*Option2 variable will be set to "1" onlt if the boolean value if true*/}} {{ CC = $params.some_bool_parameter : "1"}} {{ }} {{ /* This is currently supported */}} {{ CC = $params.some_*non*_bool_parameter}} {{}}} |
Hi, Currently there is no option to set an environment variable based on boolean value within the environment directive. I think it is crucial to implement support for something like this: {{pipeline \{}} {{agent any}} {{environment \{}} {{ /* *Option1* */}} {{ condition $params.some_bool_parameter\{}} {{ CC = "1"}} {{ }}} {{ /*}} {{ ** Option2 variable will* }} {{ ** be set to "1" onlt if the boolean value if true*}} {{ ***/}} {{ CC = $params.some_bool_parameter : "1"}} {{ }} {{ /* This is currently supported */}} {{ CC = $params.some_*non*_bool_parameter}} {{}}} |
Description |
Hi, Currently there is no option to set an environment variable based on boolean value within the environment directive. I think it is crucial to implement support for something like this: {{pipeline \{}} {{agent any}} {{environment \{}} {{ /* *Option1* */}} {{ condition $params.some_bool_parameter\{}} {{ CC = "1"}} {{ }}} {{ /*}} {{ ** Option2 variable will* }} {{ ** be set to "1" onlt if the boolean value if true*}} {{ ***/}} {{ CC = $params.some_bool_parameter : "1"}} {{ }} {{ /* This is currently supported */}} {{ CC = $params.some_*non*_bool_parameter}} {{}}} |
Hi, Currently there is no option to set an environment variable based on boolean value within the environment directive. I think it is crucial to implement support for something like this: {{pipeline \{}} {{agent any}} {{environment \{}} {{ /* *Option1* */}} {{ condition $params.some_bool_parameter\{}} {{ CC = "1"}} {{ }}} {{ /*}} ** Option2 variable will* {{ ** be set to "1" onlt if the boolean value if true*}} {{ ***/}} {{ CC = $params.some_bool_parameter : "1"}} {{ }} {{ /* This is currently supported */}} {{ CC = $params.some_*non*_bool_parameter}} {{}}} |
Description |
Hi, Currently there is no option to set an environment variable based on boolean value within the environment directive. I think it is crucial to implement support for something like this: {{pipeline \{}} {{agent any}} {{environment \{}} {{ /* *Option1* */}} {{ condition $params.some_bool_parameter\{}} {{ CC = "1"}} {{ }}} {{ /*}} ** Option2 variable will* {{ ** be set to "1" onlt if the boolean value if true*}} {{ ***/}} {{ CC = $params.some_bool_parameter : "1"}} {{ }} {{ /* This is currently supported */}} {{ CC = $params.some_*non*_bool_parameter}} {{}}} |
Hi, Currently there is no option to set an environment variable based on boolean value within the environment directive. I think it is crucial to implement support for something like this: {{pipeline \{}} {{agent any}} {{environment \{}} {{ /* *Option1* */}} {{ condition $params.some_bool_parameter\{}} {{ CC = "1"}} {{ }}} {{ /*}} ** Option2 variable will* {{ ** be set to "1" only if the boolean value if true*}} {{ ***/}} {{ CC = $params.some_bool_parameter : "1"}} {{ }} {{ /* This is currently supported */}} {{ CC = $params.some_*non*_bool_parameter}} {{}}} |
Description |
Hi, Currently there is no option to set an environment variable based on boolean value within the environment directive. I think it is crucial to implement support for something like this: {{pipeline \{}} {{agent any}} {{environment \{}} {{ /* *Option1* */}} {{ condition $params.some_bool_parameter\{}} {{ CC = "1"}} {{ }}} {{ /*}} ** Option2 variable will* {{ ** be set to "1" only if the boolean value if true*}} {{ ***/}} {{ CC = $params.some_bool_parameter : "1"}} {{ }} {{ /* This is currently supported */}} {{ CC = $params.some_*non*_bool_parameter}} {{}}} |
Hi, Currently there is no option to set an environment variable based on boolean value within the environment directive. I think it is crucial to implement support for something like this: {{pipeline \{}} {{agent any}} {{environment \{}} {{ /* *Option1* */}} {{ condition $params.some_bool_parameter\{}}{{CC = "1"}}} {{ /*}} ** Option2 variable will* {{ ** be set to "1" only if the boolean value if true*}} {{ ***/}} {{ CC = $params.some_bool_parameter : "1"}} {{ }} {{ /* This is currently supported */}} {{ CC = $params.some_*non*_bool_parameter}} {{}}} |
Description |
Hi, Currently there is no option to set an environment variable based on boolean value within the environment directive. I think it is crucial to implement support for something like this: {{pipeline \{}} {{agent any}} {{environment \{}} {{ /* *Option1* */}} {{ condition $params.some_bool_parameter\{}}{{CC = "1"}}} {{ /*}} ** Option2 variable will* {{ ** be set to "1" only if the boolean value if true*}} {{ ***/}} {{ CC = $params.some_bool_parameter : "1"}} {{ }} {{ /* This is currently supported */}} {{ CC = $params.some_*non*_bool_parameter}} {{}}} |
Hi, Currently there is no option to set an environment variable based on boolean value within the environment directive. I think it is crucial to implement support for something like this: {code:java} {{pipeline \{}} {{agent any}} {{environment \{}} {{ /* *Option1* */}} {{ condition $params.some_bool_parameter\{}}{{CC = "1"}}} {{ /*}} ** Option2 variable will* {{ ** be set to "1" only if the boolean value if true*}} {{ ***/}} {{ CC = $params.some_bool_parameter : "1"}} {{ }} {{ /* This is currently supported */}} {{ CC = $params.some_*non*_bool_parameter}} {{}}} {code} |
Description |
Hi, Currently there is no option to set an environment variable based on boolean value within the environment directive. I think it is crucial to implement support for something like this: {code:java} {{pipeline \{}} {{agent any}} {{environment \{}} {{ /* *Option1* */}} {{ condition $params.some_bool_parameter\{}}{{CC = "1"}}} {{ /*}} ** Option2 variable will* {{ ** be set to "1" only if the boolean value if true*}} {{ ***/}} {{ CC = $params.some_bool_parameter : "1"}} {{ }} {{ /* This is currently supported */}} {{ CC = $params.some_*non*_bool_parameter}} {{}}} {code} |
Hi, Currently there is no option to set an environment variable based on boolean value within the environment directive. I think it is crucial to implement support for something like this: {code:java} pipeline{ agent any environment { /*Option1*/ condition $params.some_bool_parameter{CC = "1"} /* Option2 variable will be set to "1" only if the boolean value if true */ CC = $params.some_bool_parameter : "1" /* This is currently supported */ CC = $params.some_*non*_bool_parameter {code} |
Description |
Hi, Currently there is no option to set an environment variable based on boolean value within the environment directive. I think it is crucial to implement support for something like this: {code:java} pipeline{ agent any environment { /*Option1*/ condition $params.some_bool_parameter{CC = "1"} /* Option2 variable will be set to "1" only if the boolean value if true */ CC = $params.some_bool_parameter : "1" /* This is currently supported */ CC = $params.some_*non*_bool_parameter {code} |
Hi, Currently there is no option to set an environment variable based on boolean value within the environment directive. I think it is crucial to implement support for something like this: {code:java} pipeline{ agent any environment { /*Option1*/ condition $params.some_bool_parameter{CC = "1"} /* Option2 variable will be set to "1" only if the boolean value is true */ CC = $params.some_bool_parameter : "1" /* This is currently supported */ CC = $params.some_*non*_bool_parameter {code} |
Description |
Hi, Currently there is no option to set an environment variable based on boolean value within the environment directive. I think it is crucial to implement support for something like this: {code:java} pipeline{ agent any environment { /*Option1*/ condition $params.some_bool_parameter{CC = "1"} /* Option2 variable will be set to "1" only if the boolean value is true */ CC = $params.some_bool_parameter : "1" /* This is currently supported */ CC = $params.some_*non*_bool_parameter {code} |
Hi, Currently there is no option to set an environment variable based on boolean value within the environment directive. I think it is crucial to implement support for something like this: {code:java} pipeline{ agent any environment { /*Option1*/ condition $params.some_bool_parameter{CC = "1"} /* Option2 variable will be set to "1" only if the boolean value is true */ CC = $params.some_bool_parameter : "1" /* This is currently supported */ CC = $params.some_*non*_bool_parameter {code} |
Description |
Hi, Currently there is no option to set an environment variable based on boolean value within the environment directive. I think it is crucial to implement support for something like this: {code:java} pipeline{ agent any environment { /*Option1*/ condition $params.some_bool_parameter{CC = "1"} /* Option2 variable will be set to "1" only if the boolean value is true */ CC = $params.some_bool_parameter : "1" /* This is currently supported */ CC = $params.some_*non*_bool_parameter {code} |
Hi, Currently there is no option to set an environment variable based on boolean value within the environment directive. I think it is crucial to implement support for something like this: {code:java} pipeline{ agent any environment { /*Option1*/ condition $params.some_bool_parameter{CC = "1"} /* Option2 variable will be set to "1" only if the boolean value is true */ CC = $params.some_bool_parameter : "1" /* This is currently supported */ CC = $params.some_non_bool_parameter {code} |
Description |
Hi, Currently there is no option to set an environment variable based on boolean value within the environment directive. I think it is crucial to implement support for something like this: {code:java} pipeline{ agent any environment { /*Option1*/ condition $params.some_bool_parameter{CC = "1"} /* Option2 variable will be set to "1" only if the boolean value is true */ CC = $params.some_bool_parameter : "1" /* This is currently supported */ CC = $params.some_non_bool_parameter {code} |
Hi, Currently there is no option to set an environment variable based on boolean value within the environment directive. I think it is crucial to implement support for something like this: {code:java} pipeline{ agent any environment { /*Option1*/ condition $params.some_bool_parameter{CC = "1"} /* Option2 variable will be set to "1" only if the boolean value is true */ CC = $params.some_bool_parameter : "1" /* This is currently supported */ CC = $params.some_non_bool_parameter {code} } } |
Description |
Hi, Currently there is no option to set an environment variable based on boolean value within the environment directive. I think it is crucial to implement support for something like this: {code:java} pipeline{ agent any environment { /*Option1*/ condition $params.some_bool_parameter{CC = "1"} /* Option2 variable will be set to "1" only if the boolean value is true */ CC = $params.some_bool_parameter : "1" /* This is currently supported */ CC = $params.some_non_bool_parameter {code} } } |
Hi, Currently there is no option to set an environment variable based on boolean value within the environment directive. I think it is crucial to implement support for something like this: {code:java} pipeline{ agent any environment { /*Option1*/ condition $params.some_bool_parameter{CC = "1"} /* Option2 variable will be set to "1" only if the boolean value is true */ CC = $params.some_bool_parameter : "1" /* This is currently supported */ CC = $params.some_non_bool_parameter } } {code} |
Summary | Declarative Pipeline: add option to set variables based on user passed parameter | Declarative Pipeline: add option to set environment variables based on user passed boolean parameter in the environment directive |
Component/s | pipeline-model-definition-plugin [ 21706 ] | |
Component/s | pipeline [ 21692 ] |
Assignee | Andrew Bayer [ abayer ] |
Resolution | Won't Fix [ 2 ] | |
Status | Open [ 1 ] | Resolved [ 5 ] |
Comment |
[ Well, what if you want to have a kind of pipeline prepare where some environment variables are set based on some parameters. {{// Determine target environment based on branch and set as variable $\{TARGET_ENV}}} {{TARGET_ENV = "$\{params.PULL_REQUEST_TO_BRANCH.is('integration-branch-team1') ? 'team1' : 'local'}"}} {{TARGET_ENV = "$\{params.PULL_REQUEST_TO_BRANCH.is('integration-branch-team2') ? 'team2' : 'local'}"}} {{TARGET_ENV = "$\{params.PULL_REQUEST_TO_BRANCH.is('develop') ? 'dev' : 'local'}"}} {{// Determine test suite based on branch and set as variable $\{TEST_SUITE}}} {{TEST_SUITE = "$\{params.PULL_REQUEST_TO_BRANCH.matches('^integration-branch-team(\\d+)$') ? 'smoke_test.xml' : ''}"}} {{TEST_SUITE = "$\{params.PULL_REQUEST_TO_BRANCH.matches('^develop$') ? 'allTests.xml' : ''}"}} Or something similar. This will complain about duplicate environment variable. It would be a nice feature to be able to have a script step in the environment directive or some way to do some logic... ] |
Resolution | Won't Fix [ 2 ] | |
Status | Resolved [ 5 ] | Reopened [ 4 ] |
Comment |
[ There seems to be a bug in resolving environment variables in a condition: Consider CHANGE_REQUEST environment variable filled in by a pull request, and BRANCH_NAME, the environment variable for the branch {code:java} environment { TARGET = "${changeRequest() ? CHANGE_TARGET:BRANCH_NAME}" } {code} TARGET becomes null in case changeRequest() returns false (CI build) In case of a pull request all works well. It's as if when CHANGE_TARGET becomes null, no matter the value in BRANCH_NAME, the null will be assigned. ] |
Resolution | Not A Defect [ 7 ] | |
Status | Reopened [ 4 ] | Fixed but Unreleased [ 10203 ] |
You can do something like:
CC = "${params.some_bool_parameter ? '1' : ''}"
Which will set CC to 1 if some_bool_parameter is true, and will set it to '' otherwise. If that's not sufficient and you need to be able to have the variable be unset completely, you may need to use Scripted Pipeline instead.