我有一个运行 shell 脚本的 Jenkins 工作。当脚本直接放在构建命令字段中时,它可以完美运行。但是,如果我将脚本放在 .sh 文件中,然后从 Build 命令字段中调用它:
sh $sh_dir/deploy.sh $repo_dir $name $ref $env $site_dir
$sh_dir
是一个环境变量,其余的是作业参数。它不起作用,它在第一个命令上失败,这很简单
cd $1/$2
同样,当直接放在命令字段中时,这非常有效,但在 .sh 文件中时则不行。.sh 文件作业的输出为:
Started by user anonymous
Building in workspace /var/lib/jenkins/workspace/deploy
[deploy] $ /bin/sh -xe /tmp/hudson6229756058999358596.sh
+ /var/lib/jenkins/scripts/deploy.sh /home/repos magento master live /home/sites
cd: 1: can't cd to /home/repos/magento
是的,该目录确实存在,是的,它归jenkins
.
我要疯了,试图弄清楚这一点。
编辑: deploy.sh 的结果-x
:
Started by user anonymous
Building in workspace /var/lib/jenkins/workspace/deploy
[deploy] $ /bin/sh -xe /tmp/hudson3304816709711757032.sh
+ sh -x /var/lib/jenkins/scripts/deploy.sh /home/repos magento develop staging /home/sites
+ cd /home/repos/magento
cd: 1: can't cd to /home/repos/magento