From c859e43acd5d7ce560e6a0c373a48351d4674fa5 Mon Sep 17 00:00:00 2001 From: Kai Brennenstuhl Date: Wed, 5 Jan 2022 13:23:42 +0100 Subject: [PATCH] Bugfix: Split withEnv only on first = character --- .../lesfurets/jenkins/unit/BasePipelineTest.groovy | 2 +- .../unit/declarative/TestDeclarativePipeline.groovy | 7 +++++++ .../jenkins/jenkinsfiles/WithEnvEquals_Jenkinsfile | 12 ++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 src/test/jenkins/jenkinsfiles/WithEnvEquals_Jenkinsfile diff --git a/src/main/groovy/com/lesfurets/jenkins/unit/BasePipelineTest.groovy b/src/main/groovy/com/lesfurets/jenkins/unit/BasePipelineTest.groovy index 88e9232c..f4548dd9 100644 --- a/src/main/groovy/com/lesfurets/jenkins/unit/BasePipelineTest.groovy +++ b/src/main/groovy/com/lesfurets/jenkins/unit/BasePipelineTest.groovy @@ -269,7 +269,7 @@ abstract class BasePipelineTest { } list.each { - def item = it.split('=') + def item = it.split('=', 2) assert item.size() == 2, "withEnv list does not look right: ${list.toString()}" addEnvVar(item[0], item[1]) } diff --git a/src/test/groovy/com/lesfurets/jenkins/unit/declarative/TestDeclarativePipeline.groovy b/src/test/groovy/com/lesfurets/jenkins/unit/declarative/TestDeclarativePipeline.groovy index 10a6bde1..fa656cde 100644 --- a/src/test/groovy/com/lesfurets/jenkins/unit/declarative/TestDeclarativePipeline.groovy +++ b/src/test/groovy/com/lesfurets/jenkins/unit/declarative/TestDeclarativePipeline.groovy @@ -706,6 +706,13 @@ class TestDeclarativePipeline extends DeclarativePipelineTest { assertCallStack().contains('echo(SOMEVAR outside closure = null)') } + @Test void withEnv_can_have_equals_in_value() throws Exception { + runScript('WithEnvEquals_Jenkinsfile') + printCallStack() + assertCallStack().contains('SOMEVAR inside closure = SOMETHING=SOME_OTHER_VAR') + assertJobStatusSuccess() + } + @Test void agent_with_param_label() throws Exception { runScript('AgentParam_Jenkinsfile') printCallStack() diff --git a/src/test/jenkins/jenkinsfiles/WithEnvEquals_Jenkinsfile b/src/test/jenkins/jenkinsfiles/WithEnvEquals_Jenkinsfile new file mode 100644 index 00000000..10c304de --- /dev/null +++ b/src/test/jenkins/jenkinsfiles/WithEnvEquals_Jenkinsfile @@ -0,0 +1,12 @@ +pipeline { + agent any + stages { + stage('withenvequals') { + steps { + withEnv(["SOMEVAR=SOMETHING=SOME_OTHER_VAR"]) { + echo "SOMEVAR inside closure = ${env.SOMEVAR}" + } + } + } + } +}