-
Bug
-
Resolution: Unresolved
-
Minor
-
None
Hi - There is inconsistent behavior of environment variable interpolation with the k8s plugin and declarative pipeline.
In this case, there is inconsistent handling of a single quote vs double quote.
In scripted, only double quote works -
podTemplate(label: 'mypod', containers: [ containerTemplate(name: 'maven', image: 'maven:3.3.9-jdk-8-alpine', ttyEnabled: true, command: 'cat'), ]) { node('mypod') { stage('Get a Maven project') { withEnv(["SOME_VAR=someval"]) { //prints echo "double quote - ${SOME_VAR}" //prints literal SOMEVAR echo 'single quote - single ${SOME_VAR}' } container('maven') { stage('Build a Maven project') { withEnv(["SOME_VAR=someval"]) { //same echo "double quote -${SOME_VAR}" echo 'single quote - ${SOME_VAR}' } } } } } }
in declarative pipeline, we see that this is not as true -
pipeline { agent { kubernetes { //cloud 'kubernetes' label 'mypod' containerTemplate { name 'maven' image 'maven:3.3.9-jdk-8-alpine' ttyEnabled true command 'cat' } } } environment { TEST_VAR = 'TEST_VALUE' } stages { stage('JNLP env') { steps { echo 'Environment variables in JNLP:' //Doesn't Print sh 'echo ${TEST_VAR}' //prints sh "echo ${TEST_VAR}" //prints sh "echo ${env.TEST_VAR}" } } stage('Container env') { steps { container('maven') { echo 'Environment variables in container:' sh 'env' //PRINTS - works without double quote sh 'echo ${TEST_VAR}' } } } } }
This is something specific to the kubernetes Declarative agent, so I'm removing pipeline-model-definition-plugin from the components.