129

Using Travis CI for an existing Android project calling

$ ./gradlew build connectedCheck

I get this error:

/home/travis/build.sh: line 45: ./gradlew: Permission denied
The command "./gradlew build connectedCheck" failed and exited with 126 during .
Sid
  • 4,893
  • 14
  • 55
  • 110
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841

2 Answers2

265

It depends by the exec-permission to your unix gradlew script.

It can be fixed using the command:

git update-index --chmod=+x gradlew

A little desciption to understand the problem.
First of all you can check your permissions using:

git ls-tree HEAD

You will see:

100644 blob xxxxxxxxxxx gradlew

As you can see the file has 644 permission.

Fix it by setting the executable flag on your gradlew file changing it to 755:

git update-index --chmod=+x gradlew

Just commit and push the changes:

git commit -m "permission access for travis"

[master e80ab1b] gradlew permission access for travis
 1 file changed, 0 insertions(+), 0 deletions(-)
 mode change 100644 => 100755 gradlew

A last check running git ls-tree again to see the change:

git ls-tree HEAD

You can see:

100755 blob xxxxxxxxxxxxx   gradlew

Another way to solve this issue is to use:

before_install:
 - chmod +x gradlew

This kind of solution doesn't change the permission in your git repo, but just changes the permission runtime in the execution.

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
  • 2
    It worked. I did that in 'before_script:' in my case. Thanks! – Sudarshan Tanuku Sep 21 '16 at 19:46
  • 2
    There's no reason not to have the script checked in into git with the right permissions (I'd go for 1754). I abstain from adding additional `chmod` commands in build scripts because 1) it adds unnecessary complexity 2) won't work for other team members who clone the repo anew. – Alex Apr 24 '19 at 11:02
5
script:
 - chmod +x ./gradlew build connectedCheck

Thanks all. This code is available. The key focus is on chmod +x

Allen.Cai
  • 501
  • 6
  • 7
  • There are no such files as 'build' (well there is a directory perhaps) and 'connectedCheck' so this is unnecessary here. Better see the accepted answer – Nicofisi Apr 06 '21 at 03:35