3

我有一个 Jenkins 作业,它在远程服务器上执行一个 shell 脚本。现在我想连同 shell 脚本一起发送一些参数。下面的例子可能会让你有更多的想法。

variable1={git-URL}
variable2={branch}

我希望将此参数传递给远程机器上的 shell 脚本,并且应该像下面这样执行

#/usr/local/bin/check_out_code.sh <git-url> <branch>

如果有人可以为我指出一些解决方法,那就太好了

谢谢。

4

3 回答 3

4

您可以像 linux 中的任何其他变量一样引用任何环境变量,包括 Jenkins 参数:${VARNAME}

于 2015-05-05T15:11:45.910 回答
2

我有同样的问题。

远程机器中的参数/${xx}/$xxx未定义。因此,当您的 shell 脚本在远程机器上执行时,无法获得正确的值。

这种方式将解决问题:

ssh -t server.example.com 'export MYVAR='"'$LOCALVAR'"'; mycommand'
于 2018-04-10T09:34:44.113 回答
0

As mentioned by @Slav you can use environment/build arguments like any other environment variable in Jenkins. One thing to remember is that they get expanded before the script is executed. If you happen to be using pipeline groovy scripts, make sure you use double quotes " instead of single ':

following will not work:

sh '/usr/local/bin/check_out_code.sh ${giturl} ${branch}'

following will work:

    sh "/usr/local/bin/check_out_code.sh ${giturl} ${branch}"
于 2018-04-10T10:32:53.440 回答