SETTING UP JENKINS ON MAC OSX…..

Ved Pandey
9 min readSep 5, 2016

--

WHAT IS CONTINUOUS INTEGRATION

Continuous Integration (CI) is a development practice that requires developers to integrate code into a shared repository several times a day. Each check-in is then verified by an automated build, allowing teams to detect problems early.

• Jenkins is an open-source continuous integration software tool written in the Java programming language for testing and reporting on isolated changes in a large code base in real time. The software enables developers to find and solve defects in a code base rapidly and to automate testing of their builds.

PREREQUISITES

• A Mac Machine running Mac OSX Yosemite or higher with admin access. • Java Development Kit should be installed on the machine.
• Access to a remote repository on Git, Svn etc.

INSTALLING JENKINS

• Download Jenkins installer .pkg file from Jenkins official site and go through the installation wizard.You are done with first step.No rocket science.

SETTING UP JENKINS USER

  • The Jenkins installation wizard sets up a separate user for Jenkins on your system.To check it Go to System preferences , then Users and Groups.
  • We need to give Jenkins admin access, so click the lock button in the lower left corner and enter your password.Select the new user created by the installation wizard and check the allow user to administer checkbox.

• Select the newly created user and click change password to set a password.

  • Right click the newly created user, select the Advanced options and set the Full name as Jenkins.Initially it would be some random string.

• You can also make the system auto- login to Jenkins user by selecting login options and turning the auto- login on.

  • Click the lock to save the changes and restart the system to login into Jenkins user account.

RUNNING JENKINS — FIRST TIME

• Jenkins resides at localhost:8080.

• Open your browser, go to localhost:8080 and perform the initial setup which includes installing some recommended plugins and creating an account for security purposes.You shall land to the page as shown.

SETTING JENKINS AS A LAUNCH AGENT

  • By default Jenkins runs as a daemon.A daemon is a non interactive background process which runs as part of the overall system and is not tied to a specific user.A daemon can’t interact with GUI.
  • A big part of CI is running simulators and other GUI applications, so we’ll need another option. To fix this, you can change Jenkins to run as a Launch Agent. A launch agent runs in the background on behalf of a user.
  • To change how the Jenkins process is launched, you’ll need to edit the settings file and change its location so it will automatically start on reboots.
  • Enter the following command to unload Jenkins as a Daemon:
  • sudolaunchctlunload/Library/LaunchDaemons/org.jenkins-ci.plist
  • Next, move the .plist file, which defines how Jenkins will run, to the LaunchAgents folder:
  • sudo mv /Library/LaunchDaemons/org.jenkins-ci.plist /Library/LaunchAgents/
  • Restart the jenkins and it will run as a launch agent.

ADDING PLUGINS TO JENKINS

  • Open Jenkins in your browser and login.
  • Click Manage Jenkins and then Manage Plugins
  • Click the available plugins tab and install the following plugins: Git, Xcode , Junit , Cobertura

• Restart Jenkins.

JENKINALIZING AN XCODE PROJECT

• Make sure you have a test target in your Xcode Project.If you don’t have you can add one.Needed only if you want to run test cases, generate code coverage.

• If you have a test target, make sure your pods are included in test target as well in your pod file.

• You also need to have test cases written for your code to generate test case report and code coverage.

• For your xcode project to generate code coverage you need to enable it.Click edit scheme and then select Test.Check the gather coverage data check box.

• We also need to make the schemes shared for running them through Jenkins.

• Click manage schemes and then check the shared checkbox.

• That’s it for now, open your browser and fire up jenkins.

SETTING UP FIRST JENKINS PROJECT

• Login to Jenkins and click new item.

• Enter a name and select Freestyle Project.

• Click OK and you will land to configuration page.

SETTING UP GIT
• First we need to configure git plugin.

• From the Source Code Management Section, click Git and enter your remote repository Url.

  • Now we need to setup credentials.
  • Click the Add button and then Jenkins.
  • Add your Git credentials.You need to provide username and password.
  • You can get your username by logging into your bitbucket account and checking your profile for username.
  • Click Add button and select the added credentials.
  • After setting the credentials set the branch in branch specifier.
  • The default timeout in Jenkins Git plugin for checkout is 10 minutes which may not be enough for large projects.To change it, click add button and select Advanced clone behavior and set the suitable timeout in minutes.

• Click Apply and Save.

CHECKING OUT FROM GIT

• Click on build now to test your Git configuration.

• Jenkins will have a checkout of your project at /Users/Shared/Jenkins/Home/work space/ProjectName

SETTING UP BUILD TRIGGERS

• Build triggers let you specify when you want to build your project.

• To build your project every fifteen minutes check build periodically and specify the time in cron syntax.

SETTING UP BUILD ENVIRONMENT

• Check the delete workspace option if you want to take a new checkout everytime building the project.

• Some other options are self explanatory.

ADDING BUILD STEP — CONFIGURING GENERAL SETTINGS

• Click on the add build step button and select Xcode. • Expand the General Settings.
• Set the target.
• Check clean before build checkbox.

  • Set the configuration as Debug or Release.
    • Check the pack application and build ipa checkbox.
  • • Set the ipa filename pattern and the output directory.

CONFIGURING GENERAL SETTINGS

CODE SIGNING AND KEYCHAIN SETTINGS

  • Make sure that you have installed certificates and provisioning profiles as mentioned in Xcode code signing settings on your Jenkins machine.
  • For Debug configuration install the developer certificates and provisioning profiles and for Release configuration install the corresponding certificates and provisioning profiles in your keychain.
  • Click unlock keychain and enter the path of your keychain. • Enter the password and save the settings.

SETTING ADVANCED XCODE BUILD OPTIONS

BUILDING YOUR PROJECT

  • After saving the Xcode plugin settings, click Build Now to build your project.
  • You can check the log for the whole process as it builds your project.
  • You should have an ipa in the ipa- dir of your workspace.

RUNNING YOUR TEST CASES

• You need to add a shell to run your test cases.
• Click Add Build Step and select execute shell.
• Add the following command to run your tests.
• Click Apply and Save.Build your project to run your test cases.

GENERATING THE TEST CASE REPORT — INSTALLING

XCPRETTY OR OCUNIT2JUNIT

  • To generate test case report, we need to convert the output of previous command to xml files, so we need to install a tool XCPretty or OCUnit2Junit.
  • Open up terminal and run the following command.
  • sudo gem install xcpretty Or sudo gem install ocunit2junit.
  • You can use either of the two
  • You can find the installed gem at location /usr/local/bin/

GENERATING XML FILES FOR TESTS

• We need to pipe the output of command that runs tests so as to generate xml files for test case results.Modify the test case run command as follows:

• Save and build the project.

• Go to /Users/Shared/Jenkins/Home /workspace/ProjectName

• You will have a new folder test-reports inside which you can find your xml files

CONSUMING THE XML FILES TO GENERATE REPORTS

• Click Add post-build action and select Publish Junit test result report.
• Give the path of your test report xml files in Test report XMLs.
• Save and run to have a graphical representation of your test case results.

TEST REPORT GRAPHS

GENERATING CODE COVERAGE — SLATHERING

• Generating code coverage involves converting the Apple code coverage format profdata into xml file and then publishing it using a plugin Cobertura.

• We need to install a tool Slather for the above conversion. • Fire up terminal and execute the command as shown:

• Just like we executed a command inside shell for generating xml files for test cases we need to execute another one for generating xml files for code coverage.

• Click add build step and select execute shell.

• But this command is not gonna work.Its in a sense incomplete as we have to specify some more information.

CREATING .SLATHER.YML FILE

  • Fire up text edit and create a file with the shown contents.
  • Remember to change the format text to plain text from rich format text by clicking format and selecting make plain text.
  • Save the file at the root of your project and push to Git.You don’t need to include the file in Xcode project navigator.
  • Build your project from Jenkins and check the output directory specified in the slather command.
  • You can see the cobertura.xml file.Its profdata converted to xml for code coverage.

PUBLISHING CODE COVERAGE

• Click add post build step and select Publish Cobertura Coverage Report. • Enter the path of your cobertura xml files as shown in figure.
• Apply Save and build your project.
• You can see the coverage report after your project is built successfully.

CODE COVERAGE REPORT

THAT’S ALL FOLKS

A special thanks to Shubhang Malviya for providing invaluable guidance throughout.

Facing issues drop a mail at Ved.bhumca11@gmail.com and warshoaib@gmail.com.

--

--