Configuring Travis CI for Xcode projects

Yugantar Jain
Dev Genius
Published in
2 min readAug 24, 2020

--

Running multiple scripts and configuring for projects using CocoaPods

Travis CI logo taken from Docs

Hi,

In this article, I’ll share how to configure the .yml file of Travis in your Xcode project directory to make it run the test suite of your app automatically, run multiple scripts, and build and test projects that are using CocoaPods.

Note: this article assumes that you’ve already set-up travis in your repository and have the .travis.yml file

1. Starting point

Initially, your .travis.yml file may look something like this —

This Travis configuration would be sufficient to build your Xcode project and run the tests. However, we’d like to consider and tackle some additional use cases such as —

  1. Making Travis run some other additional script (eg. Swiftlint)
  2. Making Travis work in case the project uses a dependency manager (eg. CocoaPods)

We’ll be tackling both of these two common use-cases one-by-one in the following sections —

2. Running multiple scripts in Travis

To run multiple scripts, eg. Swiftlint + Build Xcode and Test Suite, we can configure the .travis.yml file like this —

In the above Travis configuration, we add the ability of running multiple scripts, example: run Swiftlint script along with the default xcodebuild test script.

It shall be noted, that while earlier the xcodebuild script was being run by Travis by default, we now need to specify it ourselves (along with Swiftlint, line 9-10) once we explicitly declare ‘script’.

To be able to use Swiftlint, we install it first. This can be done in the ‘install’ declaration (line 1).

3. Configuring Travis for project using CocoaPods

Till now, we’re telling Travis to build the xcode_project (line 5 in above code). However, if we use a dependency manger like CocoaPods in our project, it usually creates a new xcworkspace file which is then used for development instead of the xcodeproj file.

In this case, we also need to tell Travis to use the workspace file instead. This can be done like this —

In the above code we make a few changes to enable building of our project using CocoaPods using Travis.

  1. We change project to workspace (lines 8, 13).
  2. Install CocoaPods and Pods for the project (lines 1-5).

Thank You for Reading!

Please feel free to reach out to me and connect, check out our projects, or join our open source community:
LinkedIn, GitHub, Mentorship iOS, AnitaB.org Community

--

--