CircleCI权限拒绝运行bash脚本

时间:2015-11-26 16:08:56

标签: 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 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文件中的所有内容似乎与CircleCI docs中的示例一致。我做错了什么?

4 个答案:

答案 0 :(得分:32)

几个可能的问题:

  1. deploy.sh可能未标记为可执行文件(chmod +x deploy.sh会修复此问题)
  2. deploy.sh的第一行可能不是可运行的shell ...
  3. 如果第一个不起作用,我们可以查看deploy.sh的内容吗?

答案 1 :(得分:25)

我遇到了同样的问题。我将sh添加到命令部分的前面以使其工作。

{{1}}

希望这个解决方案可以在未来的某个时间节省每个人。

答案 2 :(得分:1)

假设您已经签入,请使用此命令将其标记为可执行到git:

git update-index --chmod=+x script.sh

参考: https://www.pixelninja.me/make-script-committed-to-git-executable/

答案 3 :(得分:0)

正如@palfrey所说,脚本可能没有被标记为可执行文件,有时即使您以前在本地计算机上的脚本上运行chmod +x,它在部署时似乎也标记为错误。 (为什么?我不知道。如果有人请赐教我!)

这是一个通用命令,用于确保脚本始终标记为可执行文件。这假设它们都位于/home/ubuntu/${CIRCLE_PROJECT_REPONAME}/scripts目录中,并且都具有.sh扩展名。如果您的目录不同,请编辑以使用您的目录。

由于shared.sh调用每个脚本顶部的所有脚本source共享脚本circle.yml,我将以下代码添加到shared.sh确保所有脚本都标记为可执行文件:

SCRIPTS="/home/ubuntu/${CIRCLE_PROJECT_REPONAME}/scripts"
find "${SCRIPTS}" | grep "\.sh$" | xargs chmod +x

像魅力一样工作。 : - )