Here is my travis.yml
file:
osx_image: xcode10.2
language: objective-c
before_install:
- travis_wait 35; cd CalendarKitDemo; pod update
script:
- xcodebuild build -workspace CalendarKitDemo.xcworkspace -scheme "CalendarKitDemo" -sdk iphonesimulator | xcpretty
notifications:
email: false
The problem is that the build is always marked as "succeeded" even if the actual xcodebuild
command exited with failure, for example, here:
"failing" job that succeeds
When I remove xcpretty
, the job passes failure/success correctly, as with this example job.
How can I both use xcpretty and pass correct values to the Travis CI on the job success / failure?
Your issue is that bash by default uses the exist code from the last command, in xcpretty. So you get the exist code from xcpretty.
You can either go and set the pipefail in your environment (set -o pipefail).
pipefail
will cause the script to exit with the first non-zero exit code.
E.g. in your Travis file
script:
- set -o pipefail
- xcodebuild build -workspace CalendarKitDemo.xcworkspace -scheme "CalendarKitDemo" -sdk iphonesimulator | xcpretty
If you want to be more explicit you can also get the exitcode from the first command (xcodebuild) bash exposes the exit codes of a pipeline in the PIPESTATUS
array.
So e.g.
- xcodebuild build -workspace CalendarKitDemo.xcworkspace -scheme "CalendarKitDemo" -sdk iphonesimulator | xcpretty && exit ${PIPESTATUS[0]}"