29

I have a circle.yml file like so:

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:

/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.sh outside of the file (under commands) everything runs fine.

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

samcorcos
  • 2,330
  • 4
  • 27
  • 40

4 Answers4

50

Several possible problems:

  1. deploy.sh might not be marked as executable (chmod +x deploy.sh would fix this)
  2. The first line of deploy.sh might not be a runnable shell...

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

Tom Parker-Shemilt
  • 1,679
  • 15
  • 26
  • if you're on windows and dev locally go here to find the equivalent for powershell and/or cmd: https://ss64.com/nt/icacls.html – nate Jun 13 '22 at 01:21
  • For me I had to add this to my yml: command: | chmod +x ./scripts/generate-pipeline-config.sh ./scripts/generate-pipeline-config.sh – Louis Cribbins Dec 14 '22 at 19:47
34

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

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

Hopefully that fix saves everyone sometime going forward.

Jesse Sanders
  • 511
  • 6
  • 13
  • I found that this solution works for executing the script, however using ```sh``` disables some extensions. see https://unix.stackexchange.com/questions/155838/shell-script-throws-a-not-found-error-when-run-from-a-sh-file-but-if-entered-ma – eczajk Jun 29 '17 at 14:30
  • 8
    @eczajk So use `- bash ./deploy.sh` instead. – MikeSchinkel Aug 23 '17 at 18:46
16

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

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

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

Adam Lane
  • 1,784
  • 19
  • 25
0

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 +x on your script at your local machine. (Why? I don't know. If someone does please enlighten me!)

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}/scripts directory and all have a .sh extension. If your directory(s) is(are) different, edit to use your directory instead.

Since all my scripts source a shared script (shared.sh) at the top of each script that are called by circle.yml I add the following code to shared.sh which ensures all scripts are marked as executable:

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

Works like a charm. :-)

MikeSchinkel
  • 4,947
  • 4
  • 38
  • 46