Create Jenkins server for Xcode project?

Tram Ho

According to wikipedia:

Jenkins is a free and open source automation server. It helps automate the parts of software development related to building, testing, and deploying, facilitating continuous integration and continuous delivery.

Jenkins supports us to work with many “version control tools” such as: CVS, Subversion, Git, Mercurial. For iOS / MacOS projects that need to deliver to QA on each pull request, the developer waiting for the pull request to be merged, then manually pulling the code to build for QA sometimes will also make developers boring, or maybe developers are busy with another task. In this article, I will learn and set up the Jenkins server to automatically check the change of a branch and build the app and deliver to QA.

Install Jenkins

First, to install Jenkins we will need to install homebrew. Next, we need to install Java

After we have installed homebrew and Java, we will proceed to install Jenkins using the following syntax:

After we have installed Jenkins, to start the server, we will run the following command in the terminal:

Once the command completes, we should be able to access the jenkins server via localhost:

User settings

When we first install and access the Jenkins server, we will need to unlock Jenkins. At this point, a screen like below will appear:

Now we just need to open the link on the screen, then copy the password and we will finish Unlock Jenkins. Next, we will need to install plugins, which can take a while. Here we will choose Install suggested plugins

Wait until the plugin installation is completed.

After we have finished installing the plugin for Jenkins server, we will be taken to a screen to create the admin account, we will proceed to fill in the following information:

After the admin account setup is complete, we will have a UI similar to the following:

Job Creation

Here, I will create a job for listening for changes to a branch. To create a new job, look at the menu on the left, choose New Item

At this step, we will name the Job, here I name it IOS and select the type for it: Freestyle project Our selection of Freestyle project will help us have more options in setting up the job.

Job settings

Step 1: Install github project

Here, at the General section, I use the Github project, so I will choose the Github project and setup as below. This will change if you install another plugin.

We will need to enter the Github project url here.

Step 2: Install Source Code Management

In this section we choose Git and add the following information:

Note: in this creadentials section we can have many ways to help Jenkins to pull code from the github project. Here I use SSH Keys.

At Branches to build , I will listen to the code changes of the develop branch, so I’ll fix the default from “master” to “develop”

Step 3: Install Build Trigger

In this step, I will select Poll SCM and assign the value for Schedule as 5 signs : “ * * * *”

Poll SCM “polls the SCM transitively for checking if any changes / new commits were made and shall build the project if any new commits were pushed since the last build

  • This 5 * sign means it will check for changes every minute You can completely change this schedule if you want. Details you can see the explanation in this link: Jenkins schedule format

Build setup

At this step, because it is building under local server, and with xcode project we can use command line tool or other tools to support build and deploy project. I will perform Add build step -> Execute shell

In this step, this is just an example, so I just print out the list of folders in the project. After the setup is complete, click Save and we proceed to create a pull request -> merge into the branch that we installed in Step 2. .

Result

After the pull request is merged into the develop branch, Jenkins will automatically check and execute the steps we configure in the Build Setup section above. At the Build job detail log console. The results I got are as follows:

End

You can completely set up a build application flow -> deliver QA -> send notifications to chatwork / slack at Build -> Execute shell I currently integrate Jenkins to run the commands of fastlane to execute. Now, if you want to wake up, contact me or learn about Fastlane tool here

Share the news now

Source : Viblo