Continuous Integration for iOS – Create a build job

Now that the Jenkins server is running as a Launch Agent, it’s time to create a build job for building and testing an app.

  1. The first step is to provide Jenkins the necessary certificates and provisioning profiles. Add them as always to the keychain of the current user.
    Attention! If the Jenkins asks for access to the Keychain, press Always allow in the appearing popup. Otherwise the build process will stop. Alternatively you can unlock the keychain via script (this exposes your password – not recommended!)Additionally I had to login to the Apple developer account in Xcode, otherwise the provisioning profiles won’t be recognised.

     $ security unlock-keychain -p <MAC_USER_PASSWORD> (<KEY_CHAIN_PATH>)
  2. Choose New Item from the left side of the Jenkins dashboard.
  3. Choose Build a free-style software project, give it a speakable name and click OK.
  4. Add a description (html is supported) that explains what the job is doing, when it is triggered and which steps are executed.
  5. Select Discard Old Builds and set Max # of builds to keep to 10.
  6. Configure Source Code Management (the repository url, credentials and the branch to build).
  7. Configure Build-Trigger (e.g. poll SCM every 2 minutes: ‘H/2 * * * *’)
  8. Choose Add build step. If you want to use the Xcode plugin, choose Xcode and fill out the parameter inputs. Or choose Execute shell if you want to follow along and use the script approach.
    If you want to leverage the full power of the script approach, have a look at this build system.



Script code for building the app

  • Organise Output
  • Clean build directory before building
    mkdir -p $BUILD_DIRECTORY
  • Set Xcode version (if a different version is required)
    export DEVELOPER_DIR=/Applications/$
  • Print current Xcode version
    echo “Xcode version: “ `xcodebuild -version`
    echo “Xcode path: “ `xcode-select -print-path`
  • Build the app
    xctool 	-project ${ProjectName} \
    	-scheme JenkinsTest \
            -sdk iphoneos \
           	-configuration Release \
            clean \
  • Create IPA / Signing the app (Specify a special certificate and provisioning profile if you want to create ipa files for different use cases)
    xcrun	-sdk iphoneos \
    	PackageApplication \
            -v $BUILD_DIRECTORY/ \
            -o $BUILD_DIRECTORY/JenkinsTest.ipa \
    	#-sign “iPhone Distribution” \
    	#-embed PATH/Example_Ad_Hoc.mobileprovision
  • Zip dsym for distribution
  • Save artefacts


Script code for testing the app

  • Build tests and write test report. (If you want to run tests against multiple SDKs, have a look at the xctool documentation)
    xctool	-workspace SampleProject.xcworkspace \
           	-scheme ExampleApp \
           	-reporter plain \
           	-reporter junit:test-reports/report.xml \
           	test \
           	-freshSimulator \


Publish test results (JUnit-compatible output)

  1. Choose Add post-build action and then choose Publish JUnit test result report.
  2. Add test-report/*.xml into the field Test report XMLs.
  3. After some builds, when enough data was collected, a graph will be shown in the status view of the build job.
Test results

Test results


?  The last post in this series shows how to get insights in code quality with code metrics…

Comments are closed.