You are viewing our old blog site. For latest posts, please visit us at the new space. Follow our publication there to stay updated with tech articles, tutorials, events & more.

Continuous Integration of the Naukri India iOS with Jenkins

0.00 avg. rating (0% score) - 0 votes

Continuous Integration (CI) is a valuable addition to our workflow. Running the test cases manually is tedious. Here’s when CI comes into picture. CI tools execute test cases automatically and sends notifications to the developers. This helps increase the performance and product quality.

Jenkins is a popular Continuous Integration tool. It is a Java application that monitors and configures Jobs and can be used for Backend and Mobile end. Jenkins is responsible for the following:

  • Pulls the source code using Source Code Management (SCM).
  • Compiles the code.
  • Creation of the application builds.
  • Execution of the Test case (UT and ITs) using XCTest.
  • To get the code coverage of the Test cases.
  • Pushes the source code to another branch.

The developers don’t necessarily need to write scripts as there are hundreds of plug-in available that have been written and contributed to the Jenkins Community. Installing these plug-in is “One Click” process.

1. Jenkins Master-Slave Architecture
As we work in a distributed environment, there are multiple machines. We might need Window system to perform Windows application related task or Mac machines to perform the MAC OX related issues. In Jenkins, multiple slaves can be added as per the project requirement.
Following are the steps to configure the slaves with master:-
  • Make sure that master can ssh into slave machines. For MAC OX, we have to enable the remote sharing in System Preferences. In this case, “ssh jenkins@192.168.0.104” will be used to ssh into slave machine.
    Remote Sharing
  • A Slave Node is then added. Login to master Jenkins http://master_domian.com:8080. Click on the Manager Nodes -> New Node and fill the details.

    Node Creation

  • Configure your slave as per your requirement.
    Few points to be noted:

    • # of executor: You should put it to 1 or 2
    • Remote FS root : Better to have jenkins directory as /var/jenkins
    • Host : This must be a ip address of your slave machine
    • Username : you must run all your tests as a jenkins_user
    • Password : you can use password but I would prefer private key. It’s upto you and your companies security policy.Once you happy save the config.

    You will see window to launch new slave like this:
    Page-4-Image-3

  • Launch the Slave. Test cases would execute on slave machine
    Page-4-Image-4

2. Jenkins Build Jobs

To create a Jenkins Job, click on the “New Item” on Jenkins Dashboard. Here are the types of jobs provided:-

  • Free-style jobs: These allow us to build project on a single computer or label (group of computers, for eg “Windows-XP-32”).
  • Multi-configuration jobs: These allow us to build project on multiple computers or labels, or a mix of the two, for eg Windows-XP, Windows-Vista, Windows-7 and RedHat – useful for checking compatibility or building for multiple platforms (qt programs?)
  • Maven project: The “maven2/3 project” is a build job specially adapted to Maven projects. Jenkins understands Maven pom files and project structures, and can use the information gleaned from the pom file to reduce the work you need to do to set up your project.
  • Monitor an external job: The “Monitor an external job” build job lets you keep an eye on non-interactive processes, such as cron jobs.
    Page-5-Image-5

3. Executing the job on Mac OS Node

To restrict the Job to run on a single machine, select “Restrict where this project can be run” option. We used Mac OS as node name, for instance.
Page-5-Image-6

4. Project Source Code

Next Step is to get the latest Source Code of the project for which Source Code Management is configured. We use Git for this.

Select Git and fill the other details like GIT Url, Credential and Branch on which we have to perform the Test Cases.

Page-6-Image-7

5. Configure CocoaPod

We use CocoaPod for external libraries management. For this, Add Execute shell to perform/run the commands related to cocoaPod to configure the project with latest/defined version of the external libraries.

    • Navigate to the folder in which pod file exists
    • Run the Pod Command to install the libraries, pod install.

Page-6-Image-8

6. Execute the Test Cases

Add “Execute the shell” to perform/run the command related to the execution of the test Cases. Here is the command

xcodebuild -workspace Naukri.xcworkspace -scheme ‘Naukri_Debug_In_Release’ -sdk iphonesimulator -destination ‘platform=iOS Simulator,name=iPhone 6,OS=9.2’ test | /Users/jenkins/ocunit2junit

In this command, following are specified:-

  • Workspace
  • Scheme
  • iOS Sdk
  • destination
  • Ocunit2Junit Path :- A script that converts output from OCUnit in xcodebuild to the XML format used by JUnit. This allows for XCode builds on continuos integration servers like Jenkins, complete with test reports!

Page-7-Image-9

7. Configure JUnit Plugin

JUnit plugin shows the results of executed tests in the project. The Ocunit2Junit generates an XML file into the folder test-reports located in the root of project. The JUnit plugin has to be configured to interpret the XML file generated by the XCode plugin. The results are shown on the Jenkins web.

To configure JUnit plugin, add a post-build action and select Publish Junit test result report. Specify the location, where the XML file is generated by Ocunit2Junit, in “Test report XMLs” field.

The following figure show the configuration of the Junit plugin:-

Page-8-Image-10

8. Run the Jenkins Jobs

Click “Build with Parameters / Build Now” to execute the configured job.

Page-8-Image-11

The logs of the running jobs can be seen by clicking “Console Output” from Build history.

9. Jobs Report

Reviewing the test-cases report is important to all. We can see/review the test-case report. Go to Project’s Dashboard, there will be graph representing the Test-cases report.

Page-9-Image-12

Final Outputs

Delegating the execution of test cases to higher-performance machines simplifies the development process.