Jenkins iOS – Git, xcodebuild, TestFlight

Introduction with Jenkins iOS

If you are new to continuous integration for mobile platforms then you are in the right place. This article will explain how to setup a fully automated continuous integration environment. To do this we will 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 will 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 is pretty much the orchestrator of this process. Jenkins essentially replaces the developers duties of building, checking for errors, running unit/functional/integration tests 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 will need to install the Java Runtime if your system doesn’t already have it installed.

Jenkins iOS will install a daemon that will allow it to run on it own, whether someone is logged in or not. Jenkins installer will create a user called Jenkins. It is recommend that you 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 while logged in with Jenkins user.

Setup 3: Open the dashboard

You will setup and manage Jenkins iOS using a browser that points to a website URL. Typically it will be accessible via http://localhost:8080 while you are on 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 to be customized. Customization comes in the form of Plugins. For this tutorial, we are going to need the following Plugins:

  • Git Plugin: This will allow Jenkins to Monitor and pull code from our git repositories that will in turn trigger the build.
  • TestFlight Plugin: This will 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 server

Configuring Jenkins

Most of the default setting in the root Dashboard –> Manage Jenkins –> Configure System section is sufficient to get started. However, some routines, such as the xcodebuild, relay on xcode being installed. So you will need to ensure Jenkins execution context has any necessary environment setup.

Create a Jenkins Job

This is usually done after everything has been setup. For the purposes of this tutorial, we will have an initial job setup in advance.

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

This will give use vanilla Jenkins job that 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 have Git installed. For Mac, this comes installed along with XCode. If not, you should: Open terminal –> Execute command xcode-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 is to perform a git Clone command on your configured Repository and the designated branch. This will pull down the latest commit locally so the build can be invoked.

Using the Job that was created earlier we will configure it’s Source Control Management section to use Git. Starting at the Jenkins Dashboard you 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 see this error when setting up could not lock config file .git/config. 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 order to get this to work with a username and password I needed to pass the credentials via URL like this:https://username:[email protected]/you/example.git

At this point, if you execute your job then Jenkins should perform a fetch against your configured Git repository and clone the project files into the job’s workplace (which should be: {Jenkins Home Folder}/jobs/<Your Job Name>).

So, give it a try.

Step 3: Add and Setup SCM Polling

In the Build Triggers section of the Job Configuration screen you will 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 is too often of a schedule to run all the time but for tutorial and testing purposes it is acceptable).

Ideally, I would like to use a Git Hook to push a trigger to Jenkins but unfortunately I am using TFS with a Git bridge interface 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 Hook to trigger Jenkins builds Kohsuke Kawaguchi wrote a great post on this.

At this point, if you do a commit to your repository Jenkins will 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 has xcode, xcodebuild tools, provisioning profiles and necessary certifications installed.

The shell script I have written below performs a clean, run a build, create an signed archive and an exported ipa for adhoc deployments.

Navigate in finder or terminal to your job’s workspace (something like ~/jobs/{your Job Name}/workplace.

Create a file called iOS_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, ./JenkinsArchiveand./JenkinsIPAExport`.

xcodebuild -alltargets clean

rm -rf "./JenkinsBuild/*"

xcodebuild -target HelloJenkins PROVISIONING_PROFILE="00000000-0000-0000-0000-000000000000" CONFIGURATION_BUILD_DIR=JenkinsBuild

rm -rf "./JenkinsArchive/*"

xcodebuild -scheme HelloJenkins archive PROVISIONING_PROFILE="00000000-0000-0000-0000-000000000000" CODE_SIGN_IDENTITY="iPhone Developer: Justin Hyland (XXXXXXXXXX)" -archivePath ./JenkinsArchive/HelloJenkins.xcarchive

rm -rf "./JenkinsIPAExport/*"

xcodebuild -exportArchive -exportFormat IPA -exportProvisioningProfile iOS\ Team\ Provisioning\ Profile:\ com.yourAPP.HelloJenkins -archivePath ./JenkinsArchive/HelloJenkins.xcarchive -exportPath ./JenkinsIPAExport/HelloJenkins.ipa

If you get this error error: can‘t exec ‘/Developer/usr/bin/xcodebuild‘ (No such file or directory) you 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 each 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 then you will need to change your certificate’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 all 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 you are not required to enter a password.

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

Step 5: Add and Setup Post Build Step – Jenkins iOS TestFlight Upload

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

Once you have created a TestFlight account the configuration is simple. Navigate to the TestFlight API Doc page and get yourAPI_Token and your Team_Token.

You token 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 you need to do is Select your Token pair setup previously and enter your .ipa file location (relative to your job’s workspace folder). Additionally, you can setup a distribution list on TestFlight for sending out notifications via Jenkins upload. After you setup a distribution list on TestFlight, supply that name in the advanced section of the Jenkins Plugin. Now you have email notifications via TestFlight.

Jenkins iOS – Git, xcodebuild, TestFlight

时间: 2024-10-24 18:32:17

Jenkins iOS – Git, xcodebuild, TestFlight的相关文章

Jenkins+私有git+Xcode打包ipa总结

借鉴博客: [手把手教你利用Jenkins持续集成iOS项目](http://www.jianshu.com/p/41ecb06ae95f) [Jenkins 总结 :Mac上git iOS 自动打包](http://www.jianshu.com/p/8d4452c6f17e) 前言: 最近需要研究Jenkins打包,网上的博客很多,但借鉴过程中难免出现不适合自己的情况,下面是我基于上述借鉴博客,经历一些坑之后使用Jenkins+私有git+Xcode环境打包ipa 安装 我这里的安装是去[官

Jenkins+Saucelabs+Git+Appium+Maven+TestNG+ReportNG之环境搭建与运行

1 背景 最近学了利用Appium+Maven+TestNG(ReportNG)搭建全自动化测试环境,使用https://saucelabs.com/ 网站提供的VM平台(可以手动测试与自动化测试,并且可以多线程多设备并行测试Web,Android与IOS),通过Jenkins从Git下载测试代码并触发运行,实现真正意义上的完全自动化测试. 2 环境搭建流程与运行 下面我们从零开始以搭建环境到运行一个Demo为例来说明整个流程,具体如下步骤即可. 一.jdk 安装与Java环境变量与adb配置

解决Jenkins上git出现的“ERROR: Error fetching remote repo &#39;origin&#39;”问题

今天对清掉了Jenkins中项目的工作空间,结果构建出现“ERROR: Error fetching remote repo 'origin'”问题:网上各种找也没找到解决这个问题的方法. 后来看错误之前是“> git.exe config --local --remove-section credential # timeout=10”,不会是跟密码有关吧! 于是将url改成http://用户名:密码@ip/的格式,git配置改成不使用密码,结果OK了. 解决Jenkins上git出现的"

jenkins使用Git为源码管理(windows master && linux slave)

作为一个不太经常总结的人,工作以来碰到过太多问题!往往解决之后没有有效记录,导致再次碰到需要重新查资料解决.现在改变下习惯,努力搞的了技术. 公司最近提倡开源(以前啥都机密,即使开源也没改变多少),代码从SVN迁移至Git管理,这样导致原来记录项目日志的wiki持续集成job需要重新配置.之前的设置为:每分钟检查SVN变化,有变化就执行编译发布.改为Git后,碰到坑坑洼洼,一并列在下面. jenkins的Git插件安装 git plugin,git client plugin,github pl

Jenkins+maven+git+sonar 系统持续集成&amp;代码单测管理

Jenkins+maven+git+sonar 系统持续集成&代码单测管理 Jenkins的安装 Jenkins是基于Java开发的一种持续集成工具,用于监控持续重复的工作,功能包括: 1.持续的软件版本发布/测试项目. 2.监控外部调用执行的工作. 1.下载最新的版本(一个 war 文件).Jenkins官方网址: http://Jenkins-ci.org/ 2.运行 java -jar jenkins.war(jenkins默认使用的是内嵌的jetty服务,用户也可以布置到其它容器中.)

Jenkins获取git tags代码

配置Jenkins获取git tag代码的方式其实方法很多,目前我使用比较多的主要是通过Git Parameter 来配置动态的获取最新tags代码,主要我们首先需要安装一下Git Parameter Plug-In插件,有时候直接安装会安装失败,那就直接手动安装一下. 下载地址:http://updates.jenkins-ci.org/download/plugins/git-parameter/ 1.我们进入我们目标Jenkins任务,选择[参数化构建过程]->[添加参数]->[Git

jenkins从git读取并编译VS2010项目

初步实现使用jenkins读取git仓库并自动编译VS2010项目 1.在Windows端首先需要安装jdk,然后再安装jenkins.jenkins的启动有两种,一种是通过jenkins.war启动,另一种是jenkins配置中安装Install as Windows Service,那样系统启动时候jenkins也会启动. 2.安装Git plugin插件,在Git配置中的Path to Git executable处添加Git.exe路径:C:\Program Files (x86)\Gi

jenkins获取git上的源码

jenkins获取git上的源码会遇到三种情况,我们在这里会分别介绍一下: 一.获取git上public(公有)的项目 只需配置仓库的URL即可 jenkins下使用git获取源码的配置方法 二.获取git上的private(私有)项目 2.1 使用用户名密码 仓库的URL使用http协议 2.2 使用密钥 仓库的URL使用 ssh协议的,以git开头 原文地址: http://www.xuebuyuan.com/2042085.html

老李分享:持续集成学好jenkins之Git和Maven配置

老李分享:持续集成学好jenkins之Git和Maven配置 Jenkins专用术语,请参考下面连接: https://wiki.jenkins-ci.org/display/JENKINS/Terminology 1.通过Jenkins web页面添加Git plugin Manage Jenkins->Manage Plugins->Available中选择Git Plugin安装, 注意要填写user name和 email地址,否则日后会碰到git tag的错误 2.Jenkins服务