Integrate Ci in iOS programming with TeamCity

Tram Ho

1. Introduction.

To many people, the Continuous Integration (CI) concept is something that sounds sublime and epic. However, it is simply the integration of everyone’s code and auto-build, it helps to ensure the code can run or not and the unit tests can be run.

The CI model is as follows:

2. Basic Definitions.

  • Version Control System (VCS): the system used to track changes and version control. Examples are: Git, BitBucket.
  • CI Server: The server monitors the VCS and reports what and when it will run.
  • Build Agent: A machine to build and test according to the CI server command
  • Package manager:
  • Dependency resolution: is a technology that provides a way to install, manage, and programmatically update third-party libraries.
  • GUID / UUID: A 128-bit number that is guaranteed to be unique.

3. What do you need?

  • A server running CI, can run on many different operating systems or you can run localhost.
  • A build agent, running macOS is required. Should have high performance and need to set NoSleep mode can also be the CI server
  • Xcode needs to be installed on that build agent.
  • In this article I will use TeamCity, you can see many other CI tools.

4. Installation steps

TeamCity Settings:

  • First of all, you need to install JDK 1.8
  • Next, download TeamCity from the homepage .
  • Open Terminal and go to the bin folder in the TeamCity folder you just downloaded
  • To run TeamCity server we use the command ./runAll.sh start and to stop the server ./runAll.sh stop kill
  • Run server ci and visit localhost:8111 to continue the installation

  • Please wait a moment for the init process to complete. Then we will create the access account

Above are the initial basic steps. Next we need to initialize a project with Unit Test and push it to a Github repo (you can use other types of source code storage).

Initialize the Xcode project.

  • Create a repo on Github to manage the demo code.
  • Create a demo project with unit testing and push it to Github.

Config dependencies

Gem

  • In the project we need to install Gem. tool to assist in installing the dependencies needed for runtime. To install Gem we use the command on Terminal as follows: Sudo gem install bundle .
  • Install GemFile to define the dependencies: Bundle init and run bundle install to install them
  • Config Gemfile:
  • In Gemfile we have defined Fastlane, it supports running js commands to conduct build & test.

Fastlane

  • To initialize fastlane we run fastlane init command fastlane init will have 4 options for installation. Here I will use the manual method
  • After running, there will be 1 fastlane directory generated in your project with 2 files as follows:
  • Config FastFile: here you will write the js statements to perform the steps that we will run
  • In this file we will define running pods and have functions to build and test. You can customize as desired.

After you have fully prepared the project and the dependencies, push it all to github and continue configuring with TeamCity.

Config TeamCity.

  • Initialize project, fill in the corresponding information.
  • After finishing the project initialization, we will continue to configure the build step. Choose to build step as Command Line. We will have two basic steps: Install dependencies and build & test

  • Config VCS: Select Version Control Settings on the left and select the newly created VSC.
  • Please add the code +:refs/pull/*/head as shown in the picture to trigger when you push the pull request
  • Config more features: additional tools support, here I use 3 tools
    • Commit status publisher: show PR status
    • XML report processing: Save log of running
    • Build files clean: Delete the created files to prepare for a new run.

Config Agents:

  • When you run local, teamcity by default will treat your computer as a default agent. You can run it directly on it or you can add other machines as an agent in Agent push

Tremor.

Once you have prepared all of the above, now create pull and see what TeamCity can do!

The basic tutorial to be able to integrate with TeamCity, there are many other utilities that you can learn by yourself.

Share the news now

Source : Viblo