订阅内容
CI/CD 

Part 2: How to Setup Jenkins to build iOS .ipa and run unit tests.

A robust and agile mobile application development environment requires continuous integration and delivery. It also requires an integrated and automated unit testing process that helps bring applications to market successfully. This two-part series details my work done at Red Hat Open Innovation Labs and as a Mobile Technical Account Manager to capture these mobile innovations in a useful, repeatable way. In part one of this two-part series, I broke down the steps to create and unit test a native iOS application using Red Hat’s Mobile Application Platform. In part two, I’ll show how Jenkins can be used to automate continuous integration and unit testing of that Mobile app.

Requirements

  1. Xcode 7.3
  2. Jenkins
  3. Mac OSX El Capitan

// Fix Jenkins user

 

After installing Jenkins we need to setup the Jenkins user

  1. In mac, go to system-preferences-Users and Groups-unlock-right click on the empty user you see. Specify Full name, and reset the password. Now we have a valid Jenkins user.

screen-shot-2016-08-08-at-1-56-43-pm

  1. Run these commands to give Jenkins admin rights and add to developer group

sudo dseditgroup -o edit -a jenkins -t user admin

sudo dscl . append /Groups/_developer GroupMembership jenkins

 

Move your iPhone developer certificates to system.

Since Jenkins will be running as a system process, not as a user application, we need to give it access to the developer certificates.

  1. Using Keychain application, find your iPhoneDeveloper certificate in login
  2. Make sure to expand it to see the iOS developer part
  3. Select both and copy
  4. Select system and paste those two items

screen-shot-2016-08-08-at-10-51-53-am

Logout and Login into your mac machine as Jenkins user

Add the following plugins to Jenkins

  1. Git
  2. Xcode Integration
  3. Junit Plugin

Add SSH keys to jenkins

Add Credentials needed to do git clone. Under Credentials create a new system credential. Specify the username (same as in Red Hat Mobile Application Platform portal) and you can either generate new ssh keys or copy paste a key directly. Keep passphrase empty.

Change Xcode build folder

The new Xcode places the builds in a common folder that the Xcode plugin has issues getting to, so we need to make it relative to the workspace.

  1. Go to Xcode--->Preferences---> Locations
  2. For Derived Data select as shown below

screen-shot-2016-08-12-at-10-26-07-am

Run Jenkins as Agent

In order for Jenkins to launch the simulator, it needs to be running as an Agent and not as a daemon. Follow these steps:

  1. sudo cp /Library/LaunchDaemons/org.jenkins-ci.plist /Library/LaunchAgents/org.jenkins-ci.plist
  2. sudo launchctl unload /Library/LaunchDaemons/org.jenkins-ci.plist
  3. sudo launchctl load /Library/LaunchAgents/org.jenkins-ci.plist

Setup a new Jenkins item

Create a new Jenkins project using freestyle option and the following settings. We actually need two build steps as you will see one for *.ipa and one for running unit tests on simulator.

  1. Give your project a name.
  2. Select Git, paste the git url from Red Hat Mobile Application Platform and select the right credentials.
  3. Make sure the right branch is selected, here we have master

screen-shot-2016-08-12-at-10-32-54-am

  1. We need three build steps:
  1. Execute shell for running pod install since our Red Hat Mobile Application Platform template uses pods

screen-shot-2016-08-12-at-10-34-35-am

  1. First Xcode build step to build and archive *.ipa
  1. Select Clean before build
  2. Select Generate archive
  3. Set Configuration for Debug
  4. Select Pack application and build ipa
    1. ${BUILD_DATE} for ipa filename
    2. Output directory to artifacts

 

screen-shot-2016-08-12-at-10-37-02-am

  1. Advanced Xcode build options
  1. Xcode Schema File to helloword-ios-app
  2. Xcode Workspace File to helloworld-ios-app
  3. Build output directory /Users/Shared/Jenkins/Home/workspace/iOSBuildAndTest/DerivedData

screen-shot-2016-08-12-at-11-10-43-am

4.Second build step for running unit tests

  1. Specify Target to limit it to testing: helloworld-ios-appTest
  2. Clean before build NO ← make sure this is NO or else it deletes the artifacts
  3. Configuration Debug

screen-shot-2016-08-12-at-11-08-17-am

Advanced Xcode build options

  1. Clean test reports = yes
  2. Xcode Schema file: helloworld-ios-app
  3. SDK = iphonesimulator
  4. Custom xcodebuild arguments=  test -destination 'platform=iOS Simulator,name=iPhone 6s,OS=9.3'
  5. Xcode Workspace file = helloworld-ios-app

screen-shot-2016-08-22-at-3-12-57-pm

Post build steps

  1. Add Archive the artifacts and place the url to DerivedData/artifacts/*.ipa
  2. Add Publish JUnit test result report specify url to test-reports/*.xml

screen-shot-2016-08-12-at-10-44-49-am

Results should look like this

screen-shot-2016-08-12-at-10-51-07-am

This concludes part two of our tutorial for setting up Jenkins to build iOS native applications. In part one of our tutorial we added unit tests to our Red Hat Mobile Application Platform native iOS application.


Connect with Red Hat Services

Learn more about Red Hat Consulting
Learn more about Red Hat Training
Learn more about Red Hat Certification
Subscribe to the Training Newsletter
Follow Red Hat Services on Twitter
Follow Red Hat Open Innovation Labs on Twitter
Like Red Hat Services on Facebook
Watch Red Hat Training videos on YouTube
Follow Red Hat Certified Professionals on LinkedIn
Creative Commons License


关于作者

UI_Icon-Red_Hat-Close-A-Black-RGB

按频道浏览

automation icon

自动化

有关技术、团队和环境 IT 自动化的最新信息

AI icon

人工智能

平台更新使客户可以在任何地方运行人工智能工作负载

open hybrid cloud icon

开放混合云

了解我们如何利用混合云构建更灵活的未来

security icon

安全防护

有关我们如何跨环境和技术减少风险的最新信息

edge icon

边缘计算

简化边缘运维的平台更新

Infrastructure icon

基础架构

全球领先企业 Linux 平台的最新动态

application development icon

应用领域

我们针对最严峻的应用挑战的解决方案

Original series icon

原创节目

关于企业技术领域的创客和领导者们有趣的故事