PS article length is too long, please read the officer to simplify browsing

Let’s talk about why, as usual, not reading here will not affect the quality of the article

Jenkins has long been known as an automated server that can be highly customized to handle any project packaging. Because the company is accustomed to directly plug the phone build installation (I believe most of your friends are the same – -!). Packaging with XcodeBuilder was nothing in the early stage of the project, but once the project became large, the differences of various versions, formal stations, test stations, development mode, production mode, different models and other reasons caused our small MBP to run at high speed all the time. And because Xcode packaging is extremely slow, it can be a waste of time. So I took some time to try Jenkins’ way, and I can tell you that I’ve never met you before. At the same time, I also hope that this article can help you successfully build up, and also hope to correct the shortcomings!

A brief introduction to Jenkins

As a scalable automation server, Jenkins can be used as a simple continuous integration (CI) server or become a continuous delivery (CD) hub for any project. Its characteristics are as follows:

  • Jenkins is a standalone Java-based program that runs immediately and includes Windows, Mac OS X, and other Unix-like operating systems.

  • Easy configuration Jenkins is easy to set up and configure through its web interface, which includes instant error checking and built-in help.

  • By updating more than 1,000 plug-ins in the center, Jenkins has integrated almost all of the tools in the continuous integration and continuous delivery tool chain.

  • Extending Jenkins can be extended through its plug-in architecture, providing almost unlimited possibilities for what Jenkins can do.

  • Distributed Jenkins easily distributes work across multiple machines, helping to drive builds, testing, and deployment more quickly across multiple platforms.

In short, for our iOSer, Jenkins is a simple installation, through Git source and server xcode build configuration, easy to achieve automatic server packaging tool, no longer have to wait for the pain of Xcode in that slowly turn ah turn, so elegant packaging way, you deserve it!

2. Install Jenkins

Since Jenkins relies on Java, you need to check that the Java environment is installed before installing Jenkins. Enter the command on the terminal to check:

$ java -version

If you do not have a Java environment, go to the official website to download and install Java portal

There are two ways to install Jenkins:

  • Installation package: Download the PKG installation package from Jenkins’ official website.

  • Homebrew command line: Please ensure that Homebrew has been installed. If not, go to the official website of Homebrew and copy the commands to install Jenkins by one click:

$ brew install jenkins

The speed of the process depends on the personal network environment, I download and install about 10 minutes (PS: network is not good)

After the installation, run the following command on the terminal:

$ jenkins

To start the service, enter http://localhost:8080 in the browser for access, as shown below:

2.1. Enter the cat + password path on the terminal as described in the figure to obtain the next step of password replication.

$cat Password path

2.2. Select the recommended plug-ins to install.

2.3. Wait until the plug-in is installed.

2.4. After configuring the administrator account, the installation is completed successfully.

Configure plug-ins

Keychains and Provisioning Profiles Management are required to manage local keychain and iOS certificates. You can download the HPI file by clicking the link. You can upload and install the HPI file locally or install it by searching later

3.1. Select Manage JenKins

3.2. Select the management plug-in

3.3. Search for plug-in installation or local upload file installation

3.4. After the plug-in is installed, go back to the administration page to configure Keychains and Provisioning Profiles Management

3.5. Two types of files need to be uploaded

  • Keychain file: contains iOS certificate information. The file path is~/Library/KeychainsAs shown in figure:

Make a copy of this file and drop the suffix -db to upload it.

After the upload is successful, fill in the name of the certificate in the Code Signing Identity. You can find the certificate in the key string, directly copy the name and paste it, as shown in the picture:

  • IOS Provisioning Profile File: In iOS Provisioning, dev, DIS, ad-Hoc, etc. Then upload in the same way, the relevant information will be automatically filled in, and the fixed path will be filled in the red box/ Users/username/Library/MobileDevice/Provisioning ProfilesAs shown in figure:

OK, at this point the plug-in is configured.

4. Create a task

4.1 Click Jenkins home page > Create Item. Enter the task name and select Free Style project, next.

4.2 Fill in some description information and build package discarding plan (not necessary) in general options, as shown in the figure:

Configure the Git source

5.1 Enter the Git address, related key information (HTTPS account password or SSH key), and branch name in source code management. So here I’m using SSH and I’m going to hit Add and I’m going to create SSH key information

5.2 Enter related information in the following figure. Ensure that the ID is unique, enter the SSH private key (the private key is not the public key), and click Save. The PRIVATE KEY contains —–BEGIN OPENSSH PRIVATE KEY—– and —–END OPENSSH PRIVATE KEY—–. Attached private key view command:

$ cat ~/.ssh/id_rsa

Build configuration

6.1 Go to build options, select Add Execute Shell and then Add Xcode. If you’re not using Cocoapods or if you have third-party libraries in Git, you can skip this step and add Xcode directly

6.2 The next step is to configure Xcode to build. The following configuration information only meets the needs of bloggers, but does not mean that it is completely correct, nor does it mean that it is suitable for everyone. Each item is followed by a question mark can be expanded to view the detailed description, I suggest you have time to view in detail, in order to meet their requirements.

6.3 After completing the above configuration, select Build environment, select Keychains and Code Signing Identities and Mobile Provisioning Profiles. Select the certificate corresponding to the task packaging. Important: there is a huge pit here, if you do not unlock the Xcode configuration first, it will not show the certificate information anyway

OK, Now that all the relevant basic configuration is complete, go back to the project home page and click Build Now to start a Build task operation.

During the build process, you can also view console output for information about the current build status or failure logs.

Automatic FIR upload (Optional extension)

If you want to generate IPA after automatic upload to the distribution platform (FIR, dandelion), you can configure the relevant extension plug-in. Of course, this is not a necessary step. Here’s a demo of fir configuration: THE FIR official – Jenkins plugin configures the portal

Eight, summary

Hu ~ is really a well – illustrated article. I believe that after watching the friends are also very tired, O(∩_∩) ha ha ~. In fact, the whole process is just some tedious configuration information, such as the actual operation after a few times will find it is very simple.

This paper talked about the general configuration – source management – build environment – build – build after the operation, not only build triggers, trigger this thing as the name implies, can be automatically by the certain operations to trigger the build tasks, such as can set once every 20 minutes to build, or similar code cloud also provides some webhook triggered, If you commit code once in a branch, it automatically fires and so on.

Overall Jenkins is very powerful and highly customizable, effectively increasing delivery efficiency by a factor of N. As for its more functions and configurations, I can only continue to learn and try to find a suitable solution for myself or the company in my future work.

This article is the author’s own step pit process, if can help you, thanks for giving a little star. If there is any deficiency, please correct it. I also created an iOS wechat group to talk about technology and grow up with each other. Friends who are willing to join can add my wechat Marcuspayne remarks: Add group

Jenkins + GitLab + CocoaPod automatic packaging platform configuration (from Build to export Success)