XcodeCloud build fails with "The ci_pre_xcodebuild.sh is executable but exited with 2 exit code."

204 views Asked by At

XcodeCloud build fails with following error - The ci_pre_xcodebuild.sh is executable but exited with 2 exit code. Make sure a valid shebang line is specified if the file is a script and that the interpreter specified in the shebang line is supported on Xcode Cloud.

This is my script -

#!/bin/sh
if [[ $CI_XCODEBUILD_ACTION = 'build' ]]; then
    brew install swiftlint
    cd ..
    swiftlint --strict
fi

Please let me know how can i resolve this error?

1

There are 1 answers

1
trojanfoe On BEST ANSWER

You have violations in your swift code and that's how swiftlint is telling you. It should be outputting those violations to the console so you can see what they are.

Also cd .. is weak; use something like cd $PROJECT_DIR instead:

#!/bin/bash
if [[ $CI_XCODEBUILD_ACTION = 'build' ]]; then
    which swiftlint >/dev/null || brew install swiftlint
    (cd $PROJECT_DIR; swiftlint --strict)
fi

Also you should be running swiftlint in a pre-commit hook so such errors are can be fixed before they reach your CI.