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]}"
Related
I have about 300 UI XCTest tests which i want run in every pull request.
I use some command, like it:
xcodebuild \
-project App.xcodeproj \
-scheme App \
-sdk iphonesimulator \
-destination 'platform=iOS Simulator,name=iPhone 8,OS=15.0' \
test
But i want stopping after first failed (for save time in build server). Have any way to do it?
Update:
xcodebuild have't any flag for this.
Now i try get result stream, and check that one test is failed.
Add this lines to your script:
if test $? -eq 0
then
echo "xcodebuild succeeded"
else
echo "xcodebuild failed with " + $?
exit 1
fi
Started learning how to integrate continuous integration (CI) using Travis platform for a personal project "Building a simple framework for iOS Development on Xcode". And, after a successful run creating a .travis.yml file with a set of configurations somehow I got caught up with a bunch of errors that I'm not quite familiar with.
Here's a snapshot of the travis.yml file
language: swift
os: osx
osx_image: xcode10.2
script:
- set -o pipefail && xcodebuild -project SWToaster.xcodeproj -scheme SWToaster -configuration Debug -destination 'platform=iOS Simulator,OS=12.0,name=iPhone XR' ONLY_ACTIVE_ARCH=YES
- set -o pipefail && xcodebuild test-without-building -enableCodeCoverage YES -scheme SWToasterTests -destination 'platform=iOS Simulator,OS=12.0,name=iPhone XR' ONLY_ACTIVE_ARCH=YES
And here is a snapshot of error messages:
Anyone sort of help will be appreciated
Resolved the issue by making sure the following requirements are met
Listed supported iOS Simulator SDK on Travis
Checked supported Xcode version on Travis
Then updated a .travis.yml config file as follows.
language: swift
os: osx
osx_image: xcode10.2
env:
matrix:
- TEST_SDK=iphonesimulator12.2 OS=12.2 NAME='iPhone 7'
script:
- set -o pipefail && xcodebuild -version
- set -o pipefail && xcodebuild -showsdks
- set -o pipefail && xcodebuild -project SWToaster.xcodeproj -scheme SWToaster -configuration Debug -destination "platform=iOS Simulator,OS=12.0,name=iPhone XR" ONLY_ACTIVE_ARCH=YES
- set -o pipefail && xcodebuild test -enableCodeCoverage YES -project SWToaster.xcodeproj -scheme SWToaster -sdk $TEST_SDK -destination "platform=iOS Simulator,OS=$OS,name=$NAME" ONLY_ACTIVE_ARCH=YES
I have set up Travis for my repository and my script inside travis.yml contains two test commands:
xcodebuild -workspace "$WORKSPACE" -scheme "$SCHEME" -sdk "$SDK" -destination "$DESTINATION" -configuration Release ONLY_ACTIVE_ARCH=NO ENABLE_TESTABILITY=YES GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=YES GCC_GENERATE_TEST_COVERAGE_FILES=YES build test | xcpretty;
xcodebuild -workspace "$WORKSPACE" -scheme "$APP_SCHEME" -sdk "$SDK" -destination "$DESTINATION" -configuration Release ONLY_ACTIVE_ARCH=NO ENABLE_TESTABILITY=YES GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=YES GCC_GENERATE_TEST_COVERAGE_FILES=YES build test | xcpretty;
I have noticed that if test suite from first command fails, but second succeeds, build is marked as successful, which is not right, as for me.
Use && instead of ; to separate your commands. That way, if the first test suite fails, the run will abort instead of running the second test suite.
I'm running command in Travis CI:
set -o pipefail && xcodebuild -verbose -workspace APP_NAME.xcworkspace -scheme app_name -sdk iphoneos -configuration Release OBJROOT=$PWD/build SYMROOT=$PWD/build clean build CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO | xcpretty
After compiling all files Travis writes:
▸ Running script 'Rollout.io post-build'
** BUILD FAILED **
The following build commands failed:
PhaseScriptExecution Rollout.io\ post-build build/APP_NAME.build/Release-iphoneos/APP_NAME.build/Script-FBFA10E57CD7495E8662D829.sh
(1 failure)
Can someone help me with this?
I'm having some trouble with my cocoapods running Travis CI. Everything seems to install correctly, but the xcodebuild script fails
$ set -o pipefail && xcodebuild test -workspace Example/UIKitPlus.xcworkspace -scheme UIKitPlus-Example -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO | xcpretty -c
xcodebuild: error: Failed to build workspace UIKitPlus with scheme UIKitPlus-Example.
Reason: The run destination iPad 2 is not valid for Testing the scheme 'UIKitPlus-Example'.
The command "set -o pipefail && xcodebuild test -workspace Example/UIKitPlus.xcworkspace -scheme UIKitPlus-Example -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO | xcpretty -c" exited with 70.
https://travis-ci.org/JamieREvans/UIKitPlus/builds/54649639
I'm not sure why this is failing, because I can run my tests on the iPad 2 simulator, using that scheme, without any issues.
Is this a Travis issue or is my Travis script wrong?
I've managed to get it build by adding a destination to the xcodebuild command line, e.g. -destination "platform=iOS Simulator,name=iPhone 6"