shell - Jenkins shell 脚本在 .sh 文件中不起作用

标签 shell jenkins

我有一个运行 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

最佳答案

评论中的讨论被带到聊天中。

最终发现问题是 Windows 行尾 (CRLF) 导致混淆。例如,目录 /home/repos/magento\r最后的 CR 真的不存在。有 Windows CIF 共享文件夹潜伏着。该解决方案将涉及研究如何将脚本转换为原生 Unix(仅限 LF)行尾。

关于shell - Jenkins shell 脚本在 .sh 文件中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13495782/

相关文章:

shell - 从 TCL 脚本在后台运行命令并格式化输出

java - 从 JAVA 运行 Bash 脚本文件

jenkins - 将 Go 测试输出转换为 XUnit

jenkins - 如何检查 Groovy 中的参数/变量是否可用于 Jenkins "Build with Parameters"

jenkins - 如何在Jenkins Groovy脚本中执行HTTP POST请求?

java - 为什么在 jenkins 扩展点中,ConsoleLogFilter 使用 OutputStream 而不是 String?

node.js - 是否有任何标准警告(stdwarn),如 stdout 和 stderr?

c++ - 在 C++ Shell 中更改目录时如何捕获无权限错误?

复制 Bash 的信号终止消息

docker - Jenkins 的示例管道显然无法正常工作