Build your Xcode app
VSTS | TFS 2018 | TFS 2017.2
Visual Studio Team Services (VSTS) and Team Foundation Server (TFS) provide a highly customizable continuous integration (CI) process to automatically build and package your Xcode app whenever your team pushes or checks in code. In this quickstart you learn how to define your CI process.
- A VSTS account. If you don't have one, you can create one for free. If your team already has one, then make sure you are an administrator of the team project you want to use.
While the simplest way to try this quickstart is to use a VSTS account, you can also use a TFS server instead.
First, you will need a build agent configured on a Mac machine. You may use one of the following:
- The Hosted macOS Preview agent provided by VSTS, or
- Provide your own agent by opening the macOS Terminal app on your Mac and following these setup instructions. The agent will automatically register itself with VSTS / TFS when you start it for the first time. Your Mac also needs to have Node.js, Xcode, and xcpretty (for testing) installed.
Get the sample code
You can copy this sample app code directly into your version control system so that it can be accessed by your CI build process. To get started, copy this URL to your clipboard:
To import the sample app into a Git repo in VSTS or TFS:
On the Code hub for your team project in VSTS/TFS, select the option to Import repository.
In the Import a Git repository dialog box, paste the above URL into the Clone URL text box.
Click Import to copy the sample code into your Git repo.
The sample provided here is an iOS app, but the concepts described here translate to other Xcode builds such as for macOS, tvOS, and watchOS apps. Results from running tests are published to VSTS using xcpretty. That is why you will need to have xcpretty installed if you are using your own Mac machine to perform builds, since xcpretty is not part of Xcode itself.
Set up continuous integration
A continuous integration (CI) process automatically builds and tests code every time a team member commits changes to version control. Here you'll create a CI build definition that helps your team keep the master branch clean.
Create a new build definition.
In the right panel, click Xcode, and then click Apply.
You now see all the tasks that were automatically added to the build definition by the template. These are the steps that will automatically run every time you check in code.
For the Agent queue, select Hosted macOS Preview or a queue that includes the Mac agent you set up.
For the Scheme, enter
Make sure that each of the Xcode steps are set to use version 4.* or later.
Click Get sources and then:
Click the Triggers tab in the build definition. Enable the Continuous Integration trigger. This will ensure that the build process is automatically triggered every time you commit a change to your repository.
Click Save & queue to kick off your first build. On the Save build definition and queue dialog box, click Save & queue.
A new build is started. You'll see a link to the new build on the top of the page. Click the link to watch the new build as it happens.
If you encounter a "User interaction not allowed" error when running the agent as a launch agent, on the Xcode task, you will either need enable the "Unlock default keychain" option, or switch to referencing signing certificates using a file. See Sign your mobile app for details.
If you run into issues with your tests hanging and/or not being able to start the iOS Simulator at times, you can add the Command Line task to run the
killall tool with "Simulator" as an argument (i.e.
killall "Simulator"). This will force the simulator to shut down in the event it is hung. Exercise care when running the command if you have multiple agents running for the same user and that you do not accidently kill other processes.
View the build summary
Once the build completes, select the build number to view a summary of the build.
Notice the various sections in the build summary - the source version of the commit in build details section, list of all associated changes, links to work items associated with commits, and test results. When the build is automatically triggered by a push to your Git repository, these sections are populated with all the relevant information.
To sign your application with a certificate and provisioning profile as part of CI, see Sign your mobile app.
If you plan to use your own Xcode project for this quickstart, an additional step is required to configure your project for a CI environment. Mark a scheme of your Xcode project as "Shared" and add it to source control to be used during your CI builds. Follow these steps:
In Xcode, open your project and go to Product > Scheme > Manage Schemes...
Enable Shared next to the scheme you want to use during CI. Remember the name of the scheme you shared as we will reference it later.
Now add the new files and folders in your .xcodeproj folder (specifically the xcsharedata folder to source control).