Using Xcode Server for iOS Continuous Integration
Xcode Server is a valid CI tool for iOS apps, with static analysis, testing, building, archiving, and reporting mechanisms — but we must consider the cost of managing CI server machines.
Join the DZone community and get the full member experience.Join For Free
continuous integration is an integral part of the ios development process, which gives early feedback when something breaks during application development. in an agile application development, producing working app is not only writing good code but also setting up infrastructure to deliver it continuously. the process of continuous integration and automating the build can help to achieve continuous delivery. there are various continuous integration tools available in the market that can be used on the ios team. the ci server solution can be self-hosted or cloud-hosted. you can get a whole list of ci servers here with recommendations.
in ios development, we have few options for a self-hosted ci server, including xcode server , jenkins , and teamcity . if you are looking for cloud solutions, then there are some promising services, such as travisci , circleci , buddybuild , bitrise , and greenhouseci .
there are multiple tools, so the challenge is which one to choose and to evaluate why one is better than the other. cloud ci servers are easy to set up and are managed by other companies. they simply just work, if configured correctly. the other things is that when using cloud ci solutions, we don’t need someone to manage servers. however, you have to be careful of various things like privacy, cost, ease of use, availability, and platform support while using cloud-based solutions.
choosing a self-hosted ci over a cloud ci has its pros and cons, so you should consider what is best for your team. xcode server seems to be an easy option for the self-hosted ci, as it is managed by apple and deeply integrated with xcode. in this post, we'll see the pros and cons of using xcode server for ios continuous integration.
brief introduction to xcode server
xcode server is a continuous integration platform developed by apple for analyzing, building, testing, and archiving ios and macos apps. painful parts in ios development are certificates and provisioning profiles. it became more hectic when we wanted to set up certificates and profiles on the ci server.
the latest version of xcode server solved lots of issues with certificates and profiles. xcode server is very tightly coupled with xcode, so it became painless to set up and use xcode server to perform continuous integration. apple has very comprehensive documentation on xcode server setup for ci. however, i wrote a short tutorial to set up the latest macos server to run xcode bot. you can refer those guides to get started with xcode server. xcode server has following features:
- free or cheap solution.
- self-hosted and deeply integrated with xcode.
- device testing.
- over-the-air (ota) installation.
- managed and maintained by apple.
xcode server has all these features, but some people struggled to get xcode server working properly. let’s see the pros and cons of using xcode server.
xcode server pros
xcode server is only designed to work with apple operating systems. it stands out from other self-hosted ci solutions like jenkins and teamcity because it’s managed by apple. the other options like jenkins and teamcity are managed by third-party companies and mostly written in java or some other programming language. xcode server has improved a lot since it was released the first time with xcode 5. the latest versions of macos server and xcode server have all the features needed to perform efficient continuous integration.
easy to set up
as mentioned in apple’s guide to continuous integration, xcode server can be set up with a few clicks if you have a mac or mac mini and the macos server . in my previous post on setting up ci with xcode server, i wrote down some basic steps to get up and running with xcode server and xcode bot creation. any ios or macos engineer can set that up within a few hours.
it’s almost free if you have paid apple developer account. you can get the macos server by redeeming your code. it will cost just under $20 if you are not an apple developer. this cost if comparatively low, as well, as it’s just a one-time investment.
deep integration with xcode
the xcode bots are directly integrated into the real xcode, not any xcode plug-in, and tied to the source code and schemes. xcode server uses the macos server. it’s real xcode running on a server, so it’s a deeply integrated ci server with xcode. developers can see all the test reports and code coverage reports straight into xcode running on a development mac. the developers can create, edit, and manage xcode bots from the local machine using xcode. there is no need to go to a web interface to manage ci jobs. however in jenkins or teamcity, we need to visit web interfaces to manage ci jobs.
painless certificates and provisioning profiles setup
one of the painful things in ios development is setting up certificates and provisioning profiles. apple introduced a new way of code signing at wwdc 2016 in the talk what’s new in xcode app signing . the process became easy and painless with xcode 8. while using xcode server, we need to copy all the certificates and profiles to the /library/developer/xcodeserver/certificates and /library/developer/xcodeserver/provisioningprofiles directories and we are done.
built-in code coverage
apple introduced this nice feature of generating code coverage in wwdc 2015 in the talk continuous integration and code coverage in xcode . the process of generating code coverage is easy; the only thing we need to do is tick the box while creating the xcode bot. the developer doesn’t need to use any other third-party tools like fastlane or xcov to configure code coverage.
now, code coverage will be generated for the for each integration. the cool thing is that it shows code coverage file-by-file so that we know where to add unit tests.
built-in real device testing
xcode server supports testing in the simulators as well as in the real devices. it has a built-in test service as shown in the above image, reducing the burden of configuring fastlane scan or scripting xcodebuild to run our unit and ui tests with xctest. once devices like iphones and ipads are attached to the server, then they start appearing in the devices tab so that we can select then for our app testing.
distributed test execution without building
previously, there was a need to build an app before testing. then, xcode 8 introduced a nice feature called build for testing in the talk
advanced testing and continuous integration
which generates an
file in the derived data that can be used to run tests without building using the latest
so that we can share this file with multiple xcode servers to enable parallel and distributed testing.
build hosting and ota installation
xcode server can
and host a build on the xcode server machine. the hosted build can be distributed to qa and product people to have a look. the build can be downloaded using server address in a browser like safari from the devices. there will an option to install the build on the devices. this reduces burden of using a build hosting service like
, as test users can download the build straight from xcode server.
rest api and environmental variables
there is an option to use xcode server apis and environmental variables so that we can script xcode server according to our project needs. we can use xcode server environmental variables in the pre-integration or post-integration scripts in the ‘trigger” sections. we have the ability to define our own environmental variables.
xcode server gives us ability to run bash scripts, i.e., triggers, before integration and after integration. triggers can be extremely useful for setting up dependencies, i.e., cocoapods , carthage , or swift packages , before running build as part of the pre-integration triggers. xcode server also has post-integration triggers that can be used to run other scripts to do something or send email notifications.
xcode server eliminated the need to use a lot of fastlane tools as most go the things are pre-configured. fastlane is a nice tool build on top of apple’s command line tools for the easy configuration of complex scripts. it automated ios development tasks using multiple tools to enable continuous delivery. xcode server eliminated need for scan , xcov, gym , and sigh and match .
physical access to macos server
xcode server being an self-hosted ci solution, we have physical access to machine and macos server installed on the machine. we can tweak xcode server as per our need if required. we can have fun controlling the ci server with the customization option.
xcode server cons
as we have seen, xcode server has lots of useful things, but there are some disadvantages to using xcode server. most of the previous old pains of code signing and certificates has been removed in the latest xcode. there are still some issues whiles using xcode server.
no pull request support
assuming most of us are using github as a code hosting service, we need to create pull requests before we merge code in the main branch. xcode server supports integration on different github branches, but it still doesn’t support testing of pull requests, which is the most painful part of app development. in order to enable pull requests testing, we have to write our own github webhook and generate xcode bots using xcode sever api, or we have to use open-source tools like buildasaur , which require additional setup.
build never finished
some developers complained that xcode bot keeps running forever if something goes wrong, and debugging is extremely difficult. this problem occurs when there is an issue with code signing.
extra management of servers and bots
xcode server being a self-hosted ci solution, it might not run on its own eve we configured it correctly. someone need to take care of machines and servers to make sure everything this running smoothly. it gives rise to hiring techops resources to manage those servers or use developers time to manage servers, which is costly.
ota installation fails on public domains
some xcode server users complain about configuring xcode server with public domain. ota installation doesn’t work all the time on the public domain. it throws a "couldn’t connect" error. the issue was that once you clicked on the install button, nothing happened, or that the install button never appeared. it needs additional encryption, ssl certification, and port setup to get that properly working. this post explains the pain of using xcode server.
no cross-platform support
xcode server is designed to work only with apple operating system so there isn’t any possibility to use those server machines for any other platform like android.
not suitable for the distributed teams
xcode server can be used effectively with small ios teams but if you have a big organization and want to share xcode server all over the distributed teams, then it's probably hectic to manage. it requires additional setup for domains and networking.
xcode server is a valid continuous integration solution for ios apps as it’s maintained by apple and has built-in static analysis, testing, building, archiving, and reporting mechanisms to reduce the burden on developers. however, we need to consider the cost of managing ci server machines.
what are your experiences with xcode server? do you feel it will be the number one choice for app developers? weigh in with a comment below!
Published at DZone with permission of Shashikant Jagtap, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.