90
$ ./build.sh --quiet verify

/home/travis/build.sh: line 59: ./build.sh: Permission denied. 

The command "./build.sh --quiet verify" exited with 126. 

enter image description here

Mike Lyons
  • 1,748
  • 2
  • 20
  • 33
Amit Kumar
  • 965
  • 1
  • 6
  • 11

4 Answers4

172

Looks like you need to check in the file build.sh with execution permissions. Please try the following from your own machine:

git update-index --add --chmod=+x build.sh
git commit -m 'Make build.sh executable'
git push
joepd
  • 4,681
  • 2
  • 26
  • 27
  • 13
    I've been using git since 2007 and this is the first time I have seen this solution. *slow clap* – deepelement May 09 '19 at 04:41
  • 1
    What's wrong with plain old `chmod +x build.sh && git add build.sh`? – Mateen Ulhaq May 16 '19 at 07:26
  • 4
    @MateenUlhaq that doesn't work on windows even when using git bash. So you have to add it to the git-history and then adjust the index to save the permission. – alsami May 20 '19 at 13:40
  • 1
    Before runnning `git commit`, I ran git status and it shows the same file as being tracked and untracked. I commited and was fine but next time I `git add`ed the file, the permissions were lost. – April Polubiec Mar 30 '20 at 15:58
  • Wow. Very useful coming from a Windows world but building .NET Core on Ubuntu in Azure. – Jedidja Apr 11 '20 at 10:20
  • Hey @AprilPolubiec How did you fixed that, coz I am also facing the same issue? – Rupesh May 11 '20 at 13:45
  • @Rupesh I wasn't able to... instead I just followed @Lanayx's recommendation below to add the `chmod` command in travis.yml – April Polubiec May 12 '20 at 21:09
  • Oh! Okay, Thanks for your reply @AprilPolubiec!! – Rupesh May 13 '20 at 06:03
  • My Git version (2.28.0) automatically updates the git index when you change a file's permission. I did a git diff on a file whose permissions I changed and I got the following deploy-scripts/bitbucket/install_phantomjs.sh w/deploy-scripts/bitbucket/install_phantomjs.sh changed file mode from 100644 to 100755 You can the git add and push! – Kaka Ruto Sep 30 '20 at 12:39
65

You can grant the needed permission by adding this lines to the .travis.yml

before_install:
  - chmod +x build.sh
Lanayx
  • 2,731
  • 1
  • 23
  • 35
19

Run the script using bash

Another option would be to run the script using bash, this would omit the need to modify the files' permissions.

bash path/to/file.sh

Alternatively:

sh path/to/file.sh

Note that

In this case you're not executing the script itself, you're executing bash or sh which then runs the script. Therefore the script does not need to be executable.

Make sense?

  • is there a reason one would want to run bash instead of the script? Are there benefits one way or the other? – Josh Oct 28 '17 at 22:24
  • It's just a useful way to omit having to modify file permissions. (On my mac I need sudo in order to alter file permissions. On travis-ci you can't always use sudo. I needed one way to run my tests that would work on both. And manually altering file permissions locally didn't seem like the best way...) @Josh – Jesse van der Pluijm Oct 29 '17 at 09:13
11

simply run at the path where the build.sh file is

chmod +x build.sh

mnestorov
  • 4,116
  • 2
  • 14
  • 24