Issue
In a generic pipeline I have the following:
pipeline {
agent any
parameters {
string(name: "TEST_VAR", description: "testvar")
}
stages {
stage("My stage") {
agent {
docker {
image 'myimage'
args "-u root:root"
}
}
steps {
script {
params.each {param ->
if (param.value == "") { sh "unset ${param.key}" }
}
sh 'printenv'
}
}
}
}
}
However, even if I leave the parameter empty, the printenv step prints TEST_VAR as an existing empty environment variable, as if the unset step did not work. How can I properly unset it, so that it's not declared at all?
Solution
As it turns out, jenkins parameters are immutable. I solved this issue by having the parameter called TEST_VAR_PARAM and then checking if it was empty and creating a TEST_VAR env value from its value.
Answered By - ihatenginx