Jenkins ios–git, Xcodebuild, TestFlight

Source: Internet
Author: User
Tags git hooks

Introduction with Jenkins IOS

If you were new to continuous integration for mobile platforms then you were in the right place. This article would explain how to setup a fully automated continuous integration environment. To does this we'll use the following:

    • Jenkins:our continious Integration Server application
    • Git:our code Repository,
    • Testflight:our Mobile testing distribution platform and each popular mobile platform
    • Xcodebuild:the Build tool for IOS

The life cycle of a build would look like this:

    1. Developer commits and pushes their changes to the Repo
    2. Jenkins IOS Server Job monitors Git Repo and triggers a build on the developer commit
    3. Jenkins IOS Server Job executes the Build Scripts (xcodebuild) checked in to the Repo
    4. Jenkins IOS Server uploads completed build to TestFlight

As you can tell by the workflow above, Jenkins are pretty much the orchestrator of this process. Jenkins essentially replaces the developers duties of building, checking for errors, running Unit/functional/integration t ESTs and publishes those builds out to the business or end users. Hence, the name Jenkins.

Get Jenkins installed on a Server environment

Step 1: Download Jenkins Server.

Mac

Step 2: Install Jenkins

As noted before Jenkins is build on the Java run-time. You'll need to install the Java Runtime if your system doesn ' t already has it installed.

Jenkins IOS would install a daemon that would allow it to run on it own, whether someone was logged in or not. Jenkins Installer would create a user called Jenkins. It is recommend this follow these setup to ensure the Jenkins user is correctly configured:

    1. After installing Jenkins go to into system preferences–> Group and Users.
    2. Unlock the panel. Give the "Blank" User a full name so you recognize them.
    3. Change the password to something you know.
    4. Grant the user admin rights. Here is a how-to grant admin rights tutorial.
    5. Log off the current user and log in using Jenkins. Finish This tutorial and logged in with Jenkins user.

Setup 3: Open the Dashboard

You'll setup and manage Jenkins IOS using a browser that points to a website URL. Typically it'll be accessible via http://localhost:8080 and the machine Jenkins IOS is installed.

Get Jenkins IOS Setup

Jenkins out of the box is fairly vanilla. This is good since it allows for it customized. Customization comes in the form of Plugins. For this tutorial, we is going to need the following Plugins:

    • Git plugin:this would allow Jenkins to Monitor and pulled code from our git repositories that'll in turn trigger the build .
    • TestFlight Plugin:this would streamline the post build upload process for submitting your IPA files to TestFlight .
    • Xcode plugin:this Plugin allows Jenkins to call Xcode command line tools.
Setting up the serverconfiguring Jenkins

Most of the default setting in the root Dashboard –> Manage Jenkins –> Configure System s Ection is sufficient to get started. However, some routines, such as the Xcodebuild, relay on Xcode being installed. So you'll need to ensure Jenkins execution context have any necessary environment setup.

Create a Jenkins Job

This was usually done by everything has been setup. For the purposes of this tutorial, we'll have a initial job setup in advance.

Select New Job –> Enter a job name–> Select Build a free-style software project

This would give use vanilla Jenkins job so we can customize our CI process with our desired plugins.

Using the Git Plugin

In order to use the Git Plugin, your build server needs to has git installed. For Mac, this comes installed along with XCode. If not, you should: Open terminal –> Execute commandxcode-select --install

Step 1: Install and Enable Git Plugin

At the Root of the Jenkins website select Manage Jenkins –> Select Manage Plugins

Select the Available Tab, Type Git in the search, Check the box and Install/restart Jenkins.

Step 2: Setup Source Control Management Settings

The purpose of this setup are to perform a git Clone command on your configured Repository and the designated branch. This would pull down the latest commits locally so the build can be invoked.

Using the Job that is created earlier we'll configure it's Source Control Management section to use Git. Starting at the Jenkins Dashboard your should see you list of Jobs created. Click on iOS job–> then click on Configure on the left pane menu.

The 2.0 Version of this plugin seems to fail setting credentials on a Mac. You might could not lock config file .git/config see this error when setting up. I used the 1.5 version over the 2.0 because of this BUG. You can find the Git plugin version 1.5 here.

The 1.5 version of the Git Plugin doesn ' t support credentials (only SSH). So it's order to get the username and password I needed to pass the credentials via URL like this:https://username:[email protected]/you/example.git

At the If you execute your job then Jenkins should perform a fetch against your configured Git repository and Clon E The project files into the job ' s workplace (which should is: {Jenkins Home Folder}/jobs/<Your Job Name> ).

So, give it a try.

Step 3: Add and Setup SCM Polling

In the Build Triggers sections of the Job Configuration screen you'll be able define the polling Interval. These configuration accepts cron syntax to define the polling schedule.

Simply Check the Poll SCM check box and define your cron schedule. Below illustrates a 5 min polling (this was too often of a schedule to run all the time, but for tutorial and testing Purpos ES it is acceptable).

Ideally, I would like to use a git hooks to push a trigger to Jenkins but unfortunately I am using TFS with a git bridge in Terface that doesn ' t support Git hooks. So, I am subjected to polling for changes.

If you would like for information about setting up a Git hooks to trigger Jenkins builds Kohsuke Kawaguchi wrote a Great post on this.

At this point, if you do a commit to your repository Jenkins would identify the change execute the JOB.

Go ahead, give it a try.

Step 4: Add and Setup Build Step–ios Job

This assumes your build environment have Xcode, xcodebuild tools, provisioning profiles and necessary certifications instal Led.

The shell script I has written below performs a clean, run a build, create an signed archive and an exported IPA for ADHO C deployments.

Navigate in Finder or terminal to your job ' s workspace (something like ~/jobs/{your job name}/workplace.

Create a file callediOS_Build.sh

Copy The script below into your newly create ios_build.sh file while replacing your project specific information (Provisioning_profile, code_sign_identity, exportprovisioningprofile name and an appropriate name for your Xcarchive/ipa Files

Create The following directories ./JenkinsBuild ,./jenkinsarchive and ./jenkinsipaexport '.

Xcodebuild-Alltargets CLEANRM-Rf"./jenkinsbuild/*"Xcodebuild-TargetHellojenkinsProvisioning_profile="00000000-0000-0000-0000-000000000000"Configuration_build_dir=JenkinsbuildRm-Rf"./jenkinsarchive/*"Xcodebuild-SchemeHellojenkinsArchive Provisioning_profile="00000000-0000-0000-0000-000000000000"Code_sign_identity="IPhone developer:justin Hyland (xxxxxxxxxx)" -Archivepath./Jenkinsarchive/Hellojenkins.Xcarchiverm-Rf"./jenkinsipaexport/*"Xcodebuild-Exportarchive-exportformat IPA -exportprovisioningprofile ios\ team\ provisioning\  Profile:\ com.. Hellojenkins -archivepath ./ jenkinsarchive/hellojenkins. Xcarchive -exportpath ./jenkinsipaexport /hellojenkins.                

If you get this error error: can‘t exec ‘/Developer/usr/bin/xcodebuild‘ (No such file or directory) , many need to run the following command in the terminal:

sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer

Execute This script via terminal while in your job ' s workspace directory:sh iOS_Build.sh

I would recommend running xcodebuild command one at a time to help ease any troubleshooting required.

If you where prompted for a password during the code signing/archiving command and you'll need to change your Certifica Te ' saccess control settings.

Open Keychain Access

Click System and My certificates in the left hand side of the window and Click the lock to unlock the System Keychain.

Expand Your IOS certificate to expose your private key and Double Click the key.

Click Access Control tab and ensure allow any applications to Access This item is selected.

Click Save Changes

If you where prompted for a password during the build script execution, try it again to make sure your is not required to Enter a password.

Once your build is successfully simply add a new Execute Shell command build step in Jenkins and enter and sh iOS_Build.sh y We do.

Step 5: Add and Setup Post Build step–jenkins IOS TestFlight Upload

TestFlight is a great the to distribute beta and internal applications. I have the used it with great success. Likely, there is a Jenkins Plugin to upload your automated builds.

Once you had created a TestFlight account the configuration was simple. Navigate to the TestFlight API Doc page and get your and API_Token your Team_Token .

You tokens pair needs to be setup In:jenkins dashboard–> Configure system–> Scroll to TestFlight section, Enter your tokens and Click Save.

Back to the Jenkins IOS job. All your Token pair setup previously and enter your .ipa file location (relative to need R job ' s workspace folder). Additionally, you can setup a distribution list on TestFlight for sending out notifications via Jenkins upload. After your setup a distribution list on TestFlight, supply this name in the "Advanced" section of the Jenkins Plugin. Now we have email notifications via TestFlight.

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.