Automation DevOps Featured iOSDev

Xcode9 + Xcode Server = Comprehensive iOS Continuous Integration

At WWDC 2017, Apple announces something that made almost every iOS developer smile, a session on ‘What’s New in Signing for Xcode and Xcode Server‘.  It’s hard to explain, how easy it becomes to perform Continuous Integration for Apple platforms especially iOS and macOS using Xcode 9 and Xcode Server.

CI Before Xcode 9

The iOS Continuous Integration before Xcode 9 release was very challenging. As people might have tried following things

  • Fought long battle to setup CI server machines with certificates and profiles.
  • Used Ruby based tool like Fastlane to automate the process of analysing, building, testing and code signing.
  •  Used other third party cloud CI services like TravisCI, CircleCI or self-hosted solutions like Jenkins, TeamCity to use bash scripted build or automated build from  Fastlane
  • Used tools like xctool by Facebook or Bluepill by LinkedIn to parallelize testing on multiple devices and Simulators.
  • Used third party Ruby-based tools like xcov, xcpretty for code coverage and test reporting.
  • Used Xcode Server with macOS Server app and Xcode Service for CI but still fighting with code signing and parallel execution.

Xcode Server with Xcode 9 made all these things of past. You rarely need the things above now. Xcode Server handles it all for us so easily. Thank all the developers working on developer tools to make this happen. Let’s see what’s changes

CI After Xcode 9

In Xcode 9, we have following new CI related features integrated within Xcode

  • Xcode Server is inbuilt with Xcode 9 so no need to have separate macOS app.
  • Xcode Server bot has new tabs for code signing’ and parallel testing on multiple devices and simulators with automatic provisioning of devices.
  • Automatically signing of both development and distribution signing.
  • Xcode Server creates distribution IPA with automated or manual signing
  • Xcode Sever does not launch simulator anymore still able to run in parallel.

Now, we will see that in action how easy to setup and use Xcode Server.

Setting Up Xcode Server

As mentioned earlier, Xcode Server no longer needs macOS Server app, it’s now built inside Xcode. We can see “Servers & Bots”  tab in the Xcode Preference. We can setup Xcode Server using local Mac or another Mac. We need to select the Mac and Integration user. See the GIF below to understand the process of enabling Xcode Server.

Once the service is running, we are good to create our Xcode bots to perform the continuous integration. In this tutorial, we will create a bot for both macOS and iOS application. We will create Bot for Swift package XCFit for macOS and Demo app XCS-Demo for iOS.

Creating Bots for iOS Apps – iOS

We will use Demo app XCS-Demo for iOS to set up Xcode Server. We have regular steps to create bots from  Xcode “Product -> Create Bot” and name the bot as “XCFit Bot”. Next step is to add Github Repo to the Bot. We have to add Git Repo with SSH. Xcode will ask you to trust the identity repository. You have to select “Trust” and use credential of existing SSH Key. Once successfully authorised, we should able to configure build. The build configuration is the main stage to configure what we want to perform as part of the build. We will see following main configuration options.

  • Scheme
  • Actions –  Analyse, Test, Archive and
  • Configurations

Next screen will be on scheduling the Bot integration which is self-explanatory.

Next, we have the option to add code signing. We can have the option to give Xcode Server access to developer portal and it will do everything for us. We have other option to choose a certificate from server machine for manual signing.

Automated Code Signing

Parallel Testing

We click next we have seen to select devices for testing and there is “Run tests in parallel” tick box which enables parallel execution on multiple simulators.

 

Test Reporting

Once bot finishes running tests, we get nice little reports within Xcode itself. The Test Reporting in Xcode Server looks like this:

Watch it in Action

The entire action looks like this:

Creating Bots for Swift Packages – macOS

Swift packages don’t need to be run inside simulator or devices. We can run them on macOS. Let’s create a bot for Swift package XCFit. It’s much simpler and quicker than iOS

Benefits

We just saw some shiny new features of Xcode Server but what will benefit that will bring for business or team

  • No need to write scripts for build automation  or manage CI servers for certificates and profiles
  • We can achieve continuous delivery by setting Xcode Server within few clicks

Missing Features

Although, Apple engineers made Xcode Server awesome there are couple of features still missing

  • Support for testing Pull Request  just like TravisCI
  • Uploading the IPA to iTunes Connect or TestFlight
  • do you think anything else?

Conclusion

With Xcode 9 and Xcode Server, we have almost everything in single place. It’s time to retire many tools from toolbox e.g  Fastlanexctool by Facebook or Bluepill by LinkedIn or other CI servers like TravisCI, CircleCI or self-hosted CI solutions like Jenkins, TeamCity. It’s time to completely switch to Xcode Server.

  • Jonas Reichert

    I think Xcode Server is still missing many important features, that’s why I can’t agree with your conclusion of your otherwise nice article. E.g. there is no way to say “keep only the last x integrations” of each bot, you still have to manually delete each integration via Server API. Manually deleting IntegrationAssets folder on my Mac does not reset the list of integrations anymore. etc.

    • Hi @jonas_reichert:disqusThanks a lot for your comment. I agree that there is still some maintainace needed to keep the server in sync. We can easily automate these maintenance task with scripts that can run as part of lounchd or cron job. Do you face any other issues in terms of code signing etc ?

  • Kashif Jilani

    Thats really good tutorial, Previously I need to use Mac OS X server and Bot. Now its super duper easy.

  • Hi @Matvdg:disqus Thanks a lot for your comment. I will try to answer your question as per my knowledge 🙂
    1) I think accessing remotely is still possible as long as machine in the network and has host name even if server is being embedded in Xcode. You might see the Xcode Server web page with bots status as well as OTA installation link if it works 🙂
    2) Yes. At the moment Xcode Server just doing iPA for us. We can write custom script to upload that iPA file to various places e,g Fabric, HockyApp or similar. We can also upload it to TestFlight by setting Post Script Trigger and using Apple’s xcrun agvtool .. Or you can run Fatstlane pilot action to upload it t TestFlight but using pilot is not required. You can get more info about avgtool using $ xcrun avgtool command
    Hope that help 🙂

    Don’t worry about English, I am not English too and my English is horrible as well 🙂

    • Mathieu Vandeginste

      Thanks a lot for your answer! I’ll try that asap!