The original link

preface

Jenkins is a very mature solution for iOS continuous integration. It has been used by the company before, but we have not tried to build it ourselves. This time, we tried, but we stepped on a lot of holes. Let me share some details that I personally feel should be paid attention to.

Environment introduction

  • MacOS Mojave 10.14.4 (18E226)
  • Xcode Version 10.1 (10B61)
  • Jenkins version: Jenkins ver.2.164.2

My Project integrates Cocoapods with two projects, one of which uses a Git submodule.

Begin to build

Jenkins download and install, open Jenkins interface after completion, download some plugins, and create an empty task. Next, I started to configure, configuration is divided into three steps: 1, download the source code 2, configure the certificate and packaging options 3, upload ipA.

Download the source code

I used Git for the source code and put it in Gitee, which is similar everywhere. Set the Repository URL and SSH. If the Repository URL is incorrectly configured, the interface will keep reporting errors. Submodule configuration, On screen you need to enable Additional Update submodules and Use the credentials from default remote of parent Repository The second item means that the verification of submodule is consistent with the main project. My project is consistent, so it can be checked. If not, we need to find a way. Cocoapods requires a shell in the build

 export LC_ALL=en_US.UTF-8
/usr/local/bin/pod install --verbose --no-repo-update 

Copy the code

You can try to build it first, if it works. Go to the workspace, find the directory where the project is located, copy the entire project, and compile it yourself.

Note:

  • * * * * * * * * * * * * * * * * * * * * *
  • At that time, I configured the WAY of URL clone, how always error, later changed to SSH OK.
  • export LC_ALL=en_US.UTF-8This sentence must be added, otherwise an error will be reported

Configure certificates and packaging options

Jenkins Keychains and Provisioning Profiles Management can be used to configure keychain and Provisioning Profiles. Can refer to, what introduce here is more detailed. Provisioning Profiles gets the file name of the UUID, so you can open the project with Xcode, build Settings, search Profiles and find the corresponding UUID and upload it. After that, go back to the task you just built – Setup – Build – Add build steps, add a new Xcode, and start configuring Xcode.

For General Build Settings: Development Team ID, if you don’t know where to look it up, you should first make a package with your own Xcode. The exported IPA file directory contains the Team ID in exportOptions. plist. To Generate Archive? ${WORKSPACE}/Build = ${WORKSPACE}/Build = YES

# 2 Code signing & OS X keychain options: once I open the configuration and select Read from Xcode Project, it always fails. Don’t check this option. Check Manual signing and Unlock Keychain? Keychain Password is the password used to log in to the host.

If the project is workspace, enter the path of workspace in the Xcode workspace File. Note that the suffix is not needed. However, it is recommended to fill in the other options, where Xcode Project Directory will affect the configuration of the fourth item, otherwise, info-plist will not be found, resulting in unable to change CFBundleVersion.

Versioning: This item is used to dynamically change the build number for each build, usually with ${BUILD_ID} in the Technical version.

Once you’ve configured it, you can build it and see if it works. If it fails, check the cause, or copy the source code as in the first step, try to package your project with XcodeBuild to make sure it can be packaged, and then find the problem with Jenkins configuration.

Upload the ipa

This part is very simple, I use dandelion, use Jenkins to achieve continuous integration (iOS), first go to Jenkins plugin next Upload to PGyer, then go to the task – setup – Build – add build steps, Add a Upload to pgyer with API v2, pgyer API_key can be found on the official website of dandelion, scandir is the directory where IPA resides, file wildcard is the wildcard of ipA file, note that it is not the whole process of the file. If only one IPA exists in the directory, use *. Ipa.

conclusion

Each person’s environment and requirements are different. If there is a problem during the configuration process, be sure to read the console output to see where the error occurred, the reason for the error, and the error information is more detailed. Solve the problem step by step.