CircleCI权限被拒绝运行bash脚本
我有一个CircleCI权限被拒绝运行bash脚本,bash,circleci,Bash,Circleci,我有一个circle.yml文件,如下所示: dependencies: override: - meteor || curl https://install.meteor.com | /bin/sh deployment: production: branch: "master" commands: - ./deploy.sh 当我推到Github时,我得到错误: /home/ubuntu/myproject/deploy.sh returned
circle.yml
文件,如下所示:
dependencies:
override:
- meteor || curl https://install.meteor.com | /bin/sh
deployment:
production:
branch: "master"
commands:
- ./deploy.sh
当我推到Github时,我得到错误:
/home/ubuntu/myproject/deploy.sh returned exit code 126
bash: line 1: /home/ubuntu/myproject/deploy.sh: Permission denied Action failed: /home/ubuntu/myproject/deploy.sh
当我在deploy.sh中运行位于文件外部的命令时(在commands
下),一切运行正常
circle.yml
文件中的所有内容似乎都与中的示例一致。。我做错了什么?几个可能的问题:
deploy.sh可能未标记为可执行文件(chmod+xdeploy.sh
将修复此问题)
deploy.sh的第一行可能不是可运行的shell
如果第一个不起作用,我们可以看看deploy.sh的内容吗?我也遇到了同样的问题。我在命令部分的前面添加了sh以使其正常工作
deployment:
production:
branch: "master"
commands:
- sh ./deploy.sh
希望该修复程序能在将来的某个时候为大家节省时间。正如@palfrey所说,脚本可能没有标记为可执行文件,有时在部署时似乎标记错误,即使您以前在本地计算机上对脚本运行了chmod+x
。(为什么?我不知道。如果有人知道,请指教我!)
下面是一个通用命令,用于确保脚本始终标记为可执行。这假设它们都位于/home/ubuntu/${CIRCLE\u PROJECT\u REPONAME}/scripts
目录中,并且都有.sh
扩展名。如果您的目录不同,请编辑以使用您的目录
由于我的所有脚本都是一个共享脚本(shared.sh
),位于circle.yml
调用的每个脚本的顶部,因此我将以下代码添加到shared.sh
中,以确保所有脚本都标记为可执行脚本:
SCRIPTS="/home/ubuntu/${CIRCLE_PROJECT_REPONAME}/scripts"
find "${SCRIPTS}" | grep "\.sh$" | xargs chmod +x
工作起来很有魅力。:-) 假设您已经将其签入,使用此命令将其标记为git的可执行文件:
git update-index --chmod=+x script.sh
参考:
我发现此解决方案适用于执行脚本,但是使用sh
会禁用一些扩展。请参阅@eczajk,使用-bash./deploy.sh
。