GitLab CI "./gradlew: Permission denied" and exit code 126: fix the script

By Melih Toksari, developer of MergeBell · Updated · 2 min read

Short answer

"Permission denied" when a GitLab CI job runs ./gradlew, ./mvnw or another script, followed by ERROR: Job failed: exit code 126 on the Docker executor, means the file isn't executable in the job's checkout. Git stores one executable bit for each file, and a script added from Windows, or created without chmod +x, is stored as mode 100644, so the runner checks it out without execute permission. Commit the bit with git update-index --chmod=+x gradlew, or in the job, run the script through its interpreter, such as sh ./gradlew, or chmod +x it first, which works unless the image runs as a non-root user. Windows line endings in the shebang line give a different error, required file not found or bad interpreter.

A job runs a script from the repository and stops at once:

$ ./gradlew build
/usr/bin/bash: line 148: ./gradlew: Permission denied
ERROR: Job failed: exit code 126

In images with only sh, the wording differs a little, but it still ends in Permission denied and exit code 126. The shell executor reports exit status 126 instead, and Kubernetes command terminated with exit code 126. The shell found the script but wasn’t allowed to run it, because the file isn’t executable in the job’s checkout. Here’s why, and how to fix it for good.

Why the file isn’t executable

Git stores one permission bit for each file: executable, mode 100755, or not, mode 100644. The runner checks the repository out with those modes, so a script runs only if its executable bit is in Git. It goes missing when:

  • The file was added from Windows. Git there can’t use the file system’s executable bit, so core.fileMode is off and new files are stored as 100644.
  • The file was created without chmod +x, or copied in by a tool that didn’t keep the permission.

To check, run this in your clone:

git ls-files -s gradlew

100644 at the start means not executable; 100755 means executable.

Fix it in the repository

git update-index --chmod=+x gradlew
git commit -m "Make gradlew executable"
git push

That works on Windows too, where chmod doesn’t change what Git records. For a file you’re adding for the first time, git add --chmod=+x deploy.sh does the same.

Or work around it in the job

build:
  script:
    - chmod +x ./gradlew
    - ./gradlew build

In an image that runs as a non-root user, chmod fails with Operation not permitted, because the files belong to root. Run the script through its interpreter instead, which doesn’t need the bit: sh ./gradlew build, or bash ./deploy.sh. Fixing the repository is still better, since every clone, on CI or not, then gets a working script.

Similar errors

  • Running a directory, such as ./build when it’s a folder: bash says Is a directory, also with exit code 126.
  • Windows line endings: when the first line ends in a carriage return, the system looks for an interpreter such as /bin/bash followed by that character. Bash 5.2 says cannot execute: required file not found and exits with 127; Bash 5.1 and earlier, and Bash 5.3, say bad interpreter: No such file or directory and exit with 126, like a missing executable bit. Convert the file to LF, and keep it that way with .gitattributes lines such as *.sh text eol=lf and /gradlew text eol=lf.
  • A command that doesn’t exist exits with 127. How the runner turns exit codes into job failures is in GitLab CI “exit code 1”.

On your phone

MergeBell shows a job’s log live, so the Permission denied line is there as soon as the shell prints it, and Retry reruns the job on the free tier. A retry hits the same error here: the fix is a commit that makes the script executable. More in how to retry a failed GitLab pipeline.

Frequently asked questions

Why does GitLab CI say "./gradlew: Permission denied"?

The script isn't executable in the job's checkout. Git records for each file whether it's executable, mode 100755, or not, mode 100644, and the runner checks files out with those modes. A script added from Windows, or created without chmod +x, is stored as 100644, so the shell can't run it, and the job fails with exit code 126.

How do I make gradlew executable in Git?

Run git update-index --chmod=+x gradlew, then commit and push. It works on Windows too, where chmod doesn't change what Git records. Afterwards, git ls-files -s gradlew shows 100755 at the start. For a file you're adding for the first time, git add --chmod=+x does the same.

Can I fix Permission denied in .gitlab-ci.yml instead?

Yes. Run it through its interpreter, such as sh ./gradlew build or bash ./deploy.sh, which doesn't need the executable bit, or run chmod +x ./gradlew first. In an image that runs as a non-root user, chmod fails with Operation not permitted, because the files belong to root. Fixing the repository is better, since every clone then gets a working script.

What does exit code 126 mean in GitLab CI?

The shell found the file but couldn't run it, usually because it isn't executable, or because it's a directory. Exit code 127 means the command wasn't found at all. GitLab Runner passes the code on, so on the Docker executor the job ends with ERROR: Job failed: exit code 126; the shell executor says exit status 126, and Kubernetes command terminated with exit code 126.

Why does my script fail with "required file not found" or "bad interpreter"?

The file has Windows line endings, so its first line ends in a carriage return, and the system looks for an interpreter such as /bin/bash followed by that character. Bash 5.2 says cannot execute: required file not found and exits with 127; Bash 5.1 and earlier, and Bash 5.3, say bad interpreter: No such file or directory and exit with 126, the same code as a missing executable bit. Convert the file to LF line endings, and keep it that way with .gitattributes lines such as *.sh text eol=lf and /gradlew text eol=lf.

Sources

Checked against these pages on 16 November 2026. GitLab changes quickly — if something here no longer matches, tell us and we will fix it.

Do this from your phone with MergeBell

Free for the whole review loop: the To-Do inbox, diffs and line comments, approve and merge, pipelines with retry, and push alerts for your To-Dos. Works with gitlab.com and self-managed GitLab 16.0+.

Get MergeBell for iPhoneGet MergeBell for Android

On the App Store for iOS 26 or later and on Google Play for Android 12 or later. An independent app, not affiliated with GitLab Inc.