Xcode build stops with a Run Script phase that exits with code 126
A Run Script build phase returns a nonzero exit code and the build failsShort answer
In a shell, status 126 means the command was found but is not executable. In an Xcode Run Script phase it nearly always means the script you call has no execute permission. Run chmod +x on it, and record the executable bit in Git so a fresh checkout or the CI machine keeps it.
Fix it fast
1Find out which cause you have
Open the failing Run Script step in the build log, read the line the script was running when it stopped, and check the permission bits of that file.
ls -l path/to/the-script.sh2Match what you see, then jump to its fix
What does the error look like?
A Run Script build phase returns a nonzero exit code and the build failsexit code 126
Cause 1 of 2
The script file has no execute permission
1Check
The shell returns 126 when a command is found but cannot be executed. List the file mode of the script the phase runs.
ls -l "$SRCROOT/scripts/build.sh"2Fix
Add the execute bit to the script.
chmod +x scripts/build.sh3Verify
The mode now shows x, and a clean build passes the phase.
ls -l scripts/build.sh
xcodebuild -scheme MyApp clean buildConfirmed by gnu.org
Cause 2 of 2
Git did not keep the executable bit for the team or CI
1Check
Git records the executable bit in the index. Compare what the index stores with the working file; the first column of the listing is the mode (100755 means executable).
git ls-files --stage scripts/build.sh2Fix
Record the executable bit in the index and commit it. The git-update-index page names this option as the workaround when the filesystem does not track the bit reliably.
git update-index --chmod=+x scripts/build.sh
git commit -m "Make build script executable"3Verify
The index now shows mode 100755.
git ls-files --stage scripts/build.shConfirmed by git-scm.com
How do I stop it coming back?
- After adding a script to the repo, run git ls-files --stage on it before the first push.
- In the phase, list the script under Input Files so Xcode knows what it reads.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Related fixes
Mobile apps
Cannot change the App Privacy answers in App Store Connect
Publish Your App Privacy Responses?
Only the Account Holder, Admin and App Manager roles can answer the App Privacy questions.
2 causes, each with a fixMobile apps
App record creation fails because you lack permission
You cannot add a new app in App Store Connect as a Developer or limited user
Only the Account Holder, an Admin or an App Manager can create an app record, and Apple blocks it until the Account Holder has signed the latest agreement.
3 causes, each with a fixMobile apps
You cannot find the button to pull your app back from review
No 'remove this version from review' message appears on the version page
There is no button called Reject Binary.
3 causes, each with a fixMobile apps
Your Apple Account cannot sign in to App Store Connect
Sign-in to App Store Connect is refused for an account that should have access
App Store Connect does not open to every Apple Account.
3 causes, each with a fixMobile apps
Apple rejected the app under Guideline 4.3, Design: Spam
Guideline 4.3(b) - Design - Spam
Guideline 4.3 is Apple's duplicate rule.
5 causes, each with a fixMobile apps
App Store Connect rejects a screenshot because it has transparency
Images can't include alpha channels or transparencies.
App Store Connect does not accept screenshots that carry an alpha channel or transparent pixels.
2 causes, each with a fix