CircleCI 权限被拒绝运行 bash 脚本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33942926/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 13:57:18  来源:igfitidea点击:

CircleCI permission denied running bash script

bashcircleci

提问by samcorcos

I have a circle.ymlfile like so:

我有一个circle.yml像这样的文件:

dependencies:
  override:
    - meteor || curl https://install.meteor.com | /bin/sh

deployment:
  production:
    branch: "master"
    commands:
      - ./deploy.sh

When I push to Github, I get the error:

当我推送到 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

When I run the commands that live inside deploy.shoutside of the file (under commands) everything runs fine.

当我运行位于deploy.sh文件外部(下commands)的命令时,一切运行正常。

Everything in the circle.ymlfile seems to be in line with the examples in the CircleCI docs.. What am I doing wrong?

circle.yml文件中的所有内容似乎都与CircleCI 文档中的示例一致。我做错了什么?

回答by Tom Parker-Shemilt

Several possible problems:

几个可能的问题:

  1. deploy.sh might not be marked as executable (chmod +x deploy.shwould fix this)
  2. The first line of deploy.sh might not be a runnable shell...
  1. deploy.sh 可能没有被标记为可执行文件(chmod +x deploy.sh会解决这个问题)
  2. deploy.sh 的第一行可能不是可运行的 shell...

If the first doesn't work, can we please see the contents of deploy.sh?

如果第一个不行,可以请我们看看deploy.sh的内容吗?

回答by Jesse Sanders

I was having the same issue. I added sh to the front of my commands section to get it to work.

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

deployment:
  production:
    branch: "master"
    commands:
      - sh ./deploy.sh

Hopefully that fix saves everyone sometime going forward.

希望这个修复可以在未来的某个时候拯救每个人。

回答by Adam Lane

Assuming you have already checked it in, use this command to flag it as executable to git:

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

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

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

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

回答by MikeSchinkel

As @palfrey says the script is probably not marked as executable, and sometimes it seems to be marked wrong on deployment even when you have previously run chmod +xon your script at your local machine. (Why? I don't know. If someone does please enlighten me!)

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

Here is a general command to use to ensure your scripts are always marked as executable. This assumes they are all located in a /home/ubuntu/${CIRCLE_PROJECT_REPONAME}/scriptsdirectory and all have a .shextension. If your directory(s) is(are) different, edit to use your directory instead.

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

Since all my scripts sourcea shared script (shared.sh)at the top of each script that are called by circle.ymlI add the following code to shared.shwhich ensures all scripts are marked as executable:

由于所有我的脚本的共享脚本shared.sh在每个脚本的顶部被称为由circle.yml我添加以下代码以shared.sh确保所有的脚本标记为可执行:

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

Works like a charm. :-)

奇迹般有效。:-)