Reputation: 7228
I have the following Jenkinsfile
node {
stage 'checkout'
deleteDir()
checkout scm
load 'LoadTheseVariables.txt'
echo "MYKEY: ${MYKEY}"
echo "REPO: ${REPO}"
bat 'echo MYKEY is %MYKEY%'
bat 'echo REPO is %REPO%'
}
The file LoadTheseVariables.txt
contains:
MYKEY="ThisIsTheKey"
REPO="ThisIsTheRepo"
The output of the Jenkins build is:
<..snip..>
[Pipeline] load
[Pipeline] { (LoadTheseVariables.txt)
[Pipeline] }
[Pipeline] // load
[Pipeline] echo
MYKEY: ThisIsTheKey
[Pipeline] echo
REPO: ThisIsTheRepo
[Pipeline] bat
[test] Running batch script
D:\Jenkins\workspace\test>echo MYKEY is
MYKEY is
[Pipeline] bat
[test] Running batch script
D:\Jenkins\workspace\test>echo REPO is
REPO is
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS
The Jenkins pipeline can see the variables but why can't my windows cmd environment see the variables? I even tried this step before the bat
commands at the end: bat 'refreshenv'
but that didn't reload the environment with those variables.
How can I load variables from a file in a Windows job and have them loaded into the environment at run time?
Upvotes: 0
Views: 1516
Reputation: 7228
The solution is to use double quotes instead of single around the bat
command. Seems to work fine.
Upvotes: 1