Use Jenkins to build a CI server developed by iOS

Source: Internet
Author: User
Tags git client

Directory

Introduction
Download and run
Jenkins Configuration
Installing the Git plugin
e-mail settings
Automated Build
Remote Warehouse Settings
Trigger Condition Settings
Compilation settings
Post-compilation Behavior settings
Unit Test
finally

Brief introduction

Continuous integration CI (continuous integration) is a development practice that increases project visibility and reduces the risk of project failure. There are many options for CI in iOS development, such as the ability to use Apple-provided bots for automated building and unit testing, with the advantage of deep integration with Xcode, which can be done in just a few steps, with the drawback that it is not flexible enough to be customizable. This article explains how to use Jenkins, a CI tool in the open source community, to build a CI environment for iOS development. If you are building a separate CI server, you will need a separate Mac machine.

Download and run

Open the official website of Jenkins and click on the right side of the page to download the latest version of the Jenkins War pack.

When the download is complete, open terminal, enter the directory where the war package is located, and execute the command:

java -jar jenkins.war --httpPort=8888

The Httpport specifies the HTTP port used by Jenkins, which is specified in 8888, and can be modified to suit specific circumstances. After Jenkins starts, open the browser to enter the address:

http://localhost:8888/

You can open the management interface of Jenkins.

Jenkins Configuration

Installing the Git plugin

Jenkins does not have a git plugin installed by default and requires manual selection of the installation. Enter the management interface of Jenkins, select the Manage Jenkins->Manage Plugins "Available" option, enter the git filter in "filter" in the upper-right corner of the page, and in all the listed results, select "Git Client Plugin" and "Git Server Plugin "These two options, then click the button" Download now and install after restart ". Wait for the plugin download to install successfully, restart Jenkins. As shown in the following:

e-mail settings

Jenkins can send email notifications at the right time, such as when an automated build fails. This requires the e-mail to be sent to the relevant settings.

To send a message using the SMTP protocol, first set up Jenkins's administrator mailbox, in Manage Jenkins->Configure System the "Jenkins location" set "System Admin e-mail address" for the required mailbox, That is, Jenkins sends the sender of the message.

Next set the message SMTP information, in the "E-mail Notification" area, click the "Advanced ..." button, and then set up, first fill out the SMTP server address, select the "Use SMTP Authentication" check box , then enter a user name and password, and finally, in test configuration by sending test e-mail, enter a test mailbox that tests whether the message can be sent successfully. If successful, there will be hints, as shown in.

Note: When setting up a mailbox, the Jenkins Admin mailbox will be the same mailbox as the one you set up in SMTP, or you'll get an error when using a QQ mailbox or a 163 mailbox.

Automated Build

In Jenkins, all tasks are in "job" units. The following is an example of creating an automated build job for the new iOS project, daily build, as a demonstration.

On the left side of Jenkins management, click "New Job", then enter the job name, enter "Dailybuild", select "Build a Free-style software project" and click "OK" to go to the next page.

Remote Warehouse Settings

Start with versioning-related settings, where we choose Git. Enter Git's warehouse address and select the branch that needs to build, and in "Additional behaviours", you can choose some additional git actions. Such as.

Tips: Jenkins uses the public key in the current user's. ssh directory for GIT-related operations.

Trigger Condition Settings

Next, set the trigger condition of the build, because it is doing daily build, so in "Build Triggers", select "Build periodically" and enter the build rule in the input box, here, Our rule is to build between 25 and 30 points per weekday, so enter "H (25-30) 18 * * 1-5" in the Input box (click the question mark to the right of the input box for a detailed description of the rules), such as.

Compilation settings

Then, make the relevant settings for the project compilation. Here, you can use the Xcode plugin that comes with Jenkins (need to install, refer to the installation method of the Git plugin above), or you can write your own script to complete. When scripting, you can write directly using Xcode's xcodebuild, or you can use the Xctool provided by Facebook. However, in this example, I use the makefile to complete the compilation package. This makefile features: Specify provisioning Profile Package compilation, generate Itms-services protocol related files and upload to the server in SCP or FTP to implement OTA function, send email notification and imessage notification. Use the makefile GitHub address here, which has instructions for use.

Click on the "Add Build Step" button, select "Execute Shell" and enter the contents in command:

#!/bin/zshmake cleanmakemake uploadmake sendEmailmake sendIMsg

Note: If you do not use imessage notifications, you can remove the first and last lines, otherwise, the default shell of Jenkins causes imessage notifications to not be sent properly.

Post-compilation Behavior settings

After the project has been successfully compiled, we can set up the compiled IPA file (even directly as an OTA file) and put it together with the relevant results of this build to provide the download. You can also send an email reminder when build fails. Set the following.

Click "Add post-build Action" to select "Archive the Artifacts" and enter "Build/*.ipa" in the input box to integrate the compiled and packaged IPA file. Click "Add post-build Action" to select "E-mail Notification", in the input box, enter the message after the compilation failed to notify the mailbox, if there are multiple, separated by white space characters, such as:

At this point, a daily build job basic setup is complete, click the "Save" button to save the settings. In the job, click "Build Now" to test the configuration we just made. If build fails, you can click "Console Output" to see the log to find the wrong place. If successful, in the corresponding build, you can see something like:

Unit Test

In this example, the unit test for the iOS project selects the Xctest framework (XCODE5, previously called ocunit) that comes with Xcode. Creating a unit Test job is as much a job as automating a build, only triggering build rules, and the build script and the compiled rules are somewhat different. Here are just a few of the different places.

The trigger rules for unit tests should be triggered every time a new commit is committed in the Git repository, so in "Build Triggers", select "Poll SCM" and write "H/10 * * *" in the rule, which means to poll the remote repository every 10 minutes and start building if there is a new commit. You can set the polling interval to suit your needs.

The next step is to enter the unit test script in build. There needs to be some preparation, first of all, because Jenkins only receives JUnit's unit test report, here to install a test report of the Ocunit format of the script execution into the JUnit report format script, the project named Ocunit2junit, the project address point here. The installation is very simple and executes at the command line gem install ocunit2junit (sudo permissions may be required). The second step is to share the project schemes and upload it to the remote repository in the current project engineering. Select "Manage schemes" in the project and click "Shared" in the pop-up menu, then add the corresponding Shared Shceme to version control in Git and upload it to the remote repository. Such as

"Build" configuration, the "Execute Shell" is still selected, the shell content is as follows:

xcodebuild test -scheme testCI -sdk iphonesimulator7.0 -destination OS=7.0,name="iPhone Retina (4-inch)" -configuration Debug  2>&1 | ocunit2junit

The unit tests here are done in the simulator, and if the test server is connected to an iOS device, it can also be set up on an iOS device, just modify the shell parameters above.

Finally, the post-compilation behavior is set, and the test report is added here. Click "Add post-build Action" and select "Publish JUnit test Result report" to enter the content test-reports/*.xml save settings.

Next in the Unit test job, click "Build Now" to test the job configuration, if configured correctly, you will see the emulator started, and then run a program, then in the results of the Build, you can see the corresponding test report, click to go there will be detailed information, such as:

At last

芈 峮 in the "Watercress iOS automated testing practice and experience" (video address, PPT address) mentioned that Jenkins can also integrate uiautomation for iOS UI Automation testing, and also released their own packaged UI testing tools ynm3k , Project address point here. After the study, write down the relevant experience.

Use Jenkins to build a CI server developed by iOS

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.