我有以下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%'
}
文件LoadTheseVariables.txt
包含:
MYKEY="ThisIsTheKey"
REPO="ThisIsTheRepo"
Jenkins构建的输出是:
<..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
Jenkins管道可以看到变量,但为什么我的windows cmd环境看不到变量呢?我甚至在最后的bat
命令之前尝试了这一步:bat 'refreshenv'
但是没有用这些变量重新加载环境。
如何从Windows作业中的文件加载变量并在运行时将它们加载到环境中?
答案 0 :(得分:1)
解决方案是在bat
命令周围使用双引号而不是单引号。似乎工作正常。