KISS

Keep It Simple Stupid

Jenkins + GHUnit - launch_msg error

| comments

It’s been a lot of time and efforts for me to set up the Jenkins CI server that would fetch new commits from git, run unit tests, build our iOS project, and publish the ipa file to a certain server.

The latest part I’d been fiddling around with recently is running unit tests automatically on each Jenkins build. They are written with GHUnit, but its CLI scripts are not compatible with the latest Xcode 4.5 and iOS SDK 6.0 out-of-box. The base manual I used is here: http://gabriel.github.com/gh-unit/docs/appledoc_include/guide_command_line.html.

First of all, the Makefile had to be altered to build a scheme in the workspace instead of a target in the project. Following this article, my improved Makefile looks this way:

(Makefile) download
1
2
3
4
5
6
7
8
9
10
11
12
13
default:
  # Set default make action here
  # xcodebuild -target Tests -configuration MyMainTarget -sdk iphonesimulator build

clean:
  #-rm -rf build/*
  xcodebuild -scheme test -workspace awesome.xcworkspace -configuration Debug -sdk iphonesimulator5.1 clean

test:
  #GHUNIT_CLI=1 xcodebuild -target Tests -configuration Debug -sdk iphonesimulator build
  GHUNIT_CLI=1 xcodebuild -scheme test -workspace awesome.xcworkspace -configuration Debug -sdk iphonesimulator5.1 build

.PHONY: test clean

Nota bene: the -sdk option explicitly specifies iphonesimulator5.1 (http://stackoverflow.com/questions/12557935/xcode-4-5-command-line-unit-testing/12655840#12655840), because the default value iphonesimulator (which is of version 6.0) produced the errors:

1
2
3
4
5
6
7
Running: "/Users/user/Library/Developer/Xcode/DerivedData/test-abc/Build/Products/Debug-iphonesimulator/test.app/test" -RegisterForSystemEvents
test[7775:707] Warning: CFFIXED_USER_HOME is not set!  It should be set to the simulated home directory.
test[7775:707] Unknown Device Type. Using UIUserInterfaceIdiomPad based on screen size
Terminating since there is no workspace.


** BUILD SUCCEEDED **

It’s a known issue and is tracked here: https://github.com/gabriel/gh-unit/issues/96.

The CFFIXED_USER_HOME warning is fixed by uncommenting lines 11-16 in the RunTests.sh script:

1
2
3
4
5
6
export CFFIXED_USER_HOME="$TEMP_FILES_DIR/iPhone Simulator User Dir" # Be compatible with google-toolbox-for-mac

if [ -d $"CFFIXED_USER_HOME" ]; then
  rm -rf "$CFFIXED_USER_HOME"
fi
mkdir -p "$CFFIXED_USER_HOME"

Configuring Jenkins with GHUnit is described here: http://gabriel.github.com/gh-unit/docs/appledoc_include/guide_ci.html. Running my Jenkins job produced the output:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
PhaseScriptExecution "Run Tests (for Command-Line Support)" /Users/Shared/Jenkins/Library/Developer/Xcode/DerivedData/test-hdladdygpxwhisfxxbxmrdenrtek/Build/Intermediates/test.build/Debug-iphonesimulator/test.build/Script-BA4CBAF81609EAC7005B495C.sh
    cd /Users/Shared/Jenkins/Home/jobs/test/workspace/native/ios/src
    /bin/sh -c /Users/Shared/Jenkins/Library/Developer/Xcode/DerivedData/test-hdladdygpxwhisfxxbxmrdenrtek/Build/Intermediates/test.build/Debug-iphonesimulator/test.build/Script-BA4CBAF81609EAC7005B495C.sh
launch_msg(): Socket is not connected
Running: "/Users/Shared/Jenkins/Library/Developer/Xcode/DerivedData/test-hdladdygpxwhisfxxbxmrdenrtek/Build/Products/Debug-iphonesimulator/test.app/test" -RegisterForSystemEvents
Test Suite 'Tests' started.

// …skipped…

Test Suite 'Tests' finished.
Executed 37 of 37 tests, with 0 failures in 0.348 seconds (0 disabled).

Failed tests:

Writing JUnit XML to:tmp/test-results.
Wrote JUnit XML successfully.
launch_msg(): Socket is not connected
Command /bin/sh failed with exit code 1


** BUILD FAILED **

After some debugging, I figured out the launch_msg(): Socket is not connected message is produced by launchctl command. My solution for now is to ignore the warnings, but launchctl returns non-zero exit code, and that’s why the build is considered failed. Replace the last line of RunTests.sh script with this:

1
2
set +o errexit
exit $RETVAL

It works finally!

Comments