在 Jenkins 作业中的远程 SSH 命令中传递变量

在 Jenkins 作业中的远程 SSH 命令中传递变量

我有一个小测试工作:

touch 22.txt
echo "wwe" > 22.txt
test=$(echo ${BUILD_NUMBER})
echo $test
ssh jenkins@srv1 "mkdir D:\myfolder\$test"
ssh jenkins@srv1 "dir D:\myfolder\"

BUILD_NUMBER意味着 Jenkins 中作业的构建数量
我的输出如下:

Running as SYSTEM
[EnvInject] - Loading node environment variables.
Building remotely on MAC-slave in workspace /Users/Admin/workspace/testmacosx
[testmacosx] $ /bin/sh -xe /var/folders/rq/4q3q1m2959q6zpgxghhrvdnw0000gn/T/jenkins1551827609931995498.sh
+ touch 22.txt
+ echo wwe
++ echo 5
+ test=5
+ echo 5
5
+ ssh jenkins@srv1 'mkdir D:\myfolder$test'
/var/folders/rq/4q3q1m2959q6zpgxghhrvdnw0000gn/T/jenkins1551827609931995498.sh: line 7: unexpected EOF while looking for matching `"'
Build step 'Execute shell' marked build as failure
Finished: FAILURE

怎么,您看到了,它在远程 ssh 命令中看不到此变量$test。我该如何传递此变量?您能帮我吗?

答案1

已解决。通过这个: ssh jenkins@srv1 "mkdir D:\myfolder\\$test" 因此,我们必须\在变量前添加

相关内容