Jenkins overview

Jenkins is a popular open source Continuous Integration tool, widely used in project development, with automated build, test, and deployment capabilities. Jenkins is written in the Java language and can run in popular servlet containers such as Tomcat or on its own. It is often used in combination with version management tools (SCM) and build tools. Common version control tools include SVN and GIT, and build tools include Maven, Ant, and Gradle.

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
Copy the code

Go to the official website to download

Click to enter the installation instructions page, you can follow the prompts to install

Install Jenkins using Homebrew package manager.

Homemade installation programJenkins - LTS.

Installation command:

  • Install the latest LTS version:brew install jenkins-lts
  • Install specific LTS versions:brew install jenkins-lts@YOUR_VERSION
  • Start Jenkins Service:brew services start jenkins-lts
  • Restart Jenkins service:brew services restart jenkins-lts
  • Updated Jenkins version:brew upgrade jenkins-lts

Installation steps

  • After starting the Jenkins service, visit http://localhost:8080, the page needs to confirm that the administrator installed, let us enter the password, the password is stored in the red directory, just take it out and fill in the input box.

  • Select the recommended plug-ins to install.

  • Wait until the plug-in installation is complete. Some plug-ins may fail to be installed. Try again until all recommended plug-ins are installed.

  • After the plug-in is installed, the system automatically switches to the configured administrator account

  • Click Save and Finish to complete the registration

Jenkins configuration

Open your browser and type localhost:8080 to open Jenkins, enter your password and click Continue.

Restart the Jenkins

Errors may occur due to some plug-in dependenciesAfter the user is created, you can restart Jenkins and log in to Jenkins using the newly created account or admin account. Restart the Jenkins method and typejenkins-lts, press Enter.

Install iOS plug-ins

IOS packaging requires keystrings to access certificates, description files, etc., so we need to install keystrings and description files plug-ins. Go to Jenkins-> System Management -> Plug-in Management to install related plug-ins, which can be searched by filtering in the upper right corner. Then select the plug-in you want to install and select install. After the installation is successful, you can choose whether to restart Jenkins. Wait until the installation is complete and restart Jenkins

Configuration key chain

Once successful, you can find the Keychains and Provisioning Profiles Management you installed in the Jenkins home page -> Provisioning Profiles Management. Click on the Provisioning Keychains and Provisioning Profiles file.Upload keychain and Provisioning Profile files.You can see the keystring path of login in the keystring, then just follow the path to find the file to upload (click Upload).Note: login.keychain-db cannot be uploaded, we need to make a copy of it and change it to login.keychain. In addition, when uploading, the path cannot be found because the repository is hidden, so use Command + Shift +. Just display it, and there you go.Note: The Code Signing Identity can be configured in multiple ways. You can Add both the notification certificate and the publishing certificate by clicking on the Add Code Sign Identity below.

Configuration Description File

First upload the Provisioning Profiles file, the file path to/Users / / your computer user name/Library/MobileDevice/Provisioning Profiles, under this path to find the corresponding project profile file upload, Drag in the terminal and it’ll show you the entire path, copy it over, and just hit Save and you’re done. NowJenkinsNo need to upload description files one by one 😁. At this point the entire plug-in configuration is complete.

Create a project

A new task

Select the first one, enter the project name, and click OK.

Build configuration

General

Source code management

I use Git. The credentials are the login account password, and the packing branch can be set according to your needsIf one is not added, see the following figure

Build environment

Select the certificate you just filled in for the plug-in.

Build (Key)

Click Add Build step, select Execute Shell, and enter the package script

The script that

-exportArchive Has a file adhoc_exportoptions. plist.You can use Xcode to export the IPA and obtain it from the exported folder. Method: There are four channels available. I split them up into four different PList files.

App-store Ad-Hoc Enterprise DevelopmentCopy the code

After package and export IPA, I need to upload internal test or application platform. I am the dandelion who uploaded the ipA, and use cURL to upload it directly to dandelion. The dandelion official provides dandelion API for specific commands, and uKey and _API_key are also available on this page

That’s it, click Save, and you’re ready to build.

Package script attached

#! /bin/sh export LANG=en_US.UTF-8 # 1. Release | debug) configuration="release" # APP_NAME="TestDome" # TARGET name TARGET_NAME="TestDome" # IPA prefix (according to the project) IPA_NAME=" test "# info.plist path #project_infoplist_path="./${TARGET_NAME}/ info.plist "#bundleShortVersion=$(/usr/libexec/PlistBuddy -c "print CFBundleShortVersionString" "${project_infoplist_path}") #bundleVersion=$(/usr/libexec/PlistBuddy -c "print CFBundleVersion" "${project_infoplist_path}") # DATE=$(DATE +%Y%m%d-%H-% m -%S) # Project file path IPANAME="${APP_NAME}_${DATE}_IPA" # ARCHIVE_NAME="${APP_NAME}_${DATE}. Xcarchive Root # project source directory (where the ${WORKSPACE} is a built-in variables in Jenkins said (Jenkins job path) : / Users/PLZ /. Jenkins/WORKSPACE/TestDome /) # CODE_PATH="${WORKSPACE}" # change the path of the ipa file ${WORKSPACE} to your own username ROOT_PATH="/Users/${username}/Desktop/Jenkins" ARCHIVE_PATH="${ROOT_PATH}/Archive/${ARCHIVE_NAME}" IPA_PATH="${ROOT_PATH}/Export/${IPANAME}" echo "ARCHIVE_PATH: ${ARCHIVE_PATH}" echo "IPA_PATH: ${IPA_PATH}" echo "IPA_PATH:\n${IPA_PATH}">> export_history.txt # Guide package (need according to the need to manually configure here: AdHoc/AppStore/Enterprise/Development) EXPORT_METHOD = "AdHoc" # Guide package configuration file path (here need to manually create the corresponding XXXExportOptionsPlist. The file, If test "$EXPORT_METHOD" = "AdHoc"; if test "$EXPORT_METHOD" = "AdHoc"; then EXPORT_METHOD_PLIST_PATH=${CODE_PATH}/ExportOptions/AdHocExportOptions.plist elif test "$EXPORT_METHOD" = "AppStore"; then EXPORT_METHOD_PLIST_PATH=${CODE_PATH}/ExportOptions/AppStoreExportOptios.plist elif test "$EXPORT_METHOD" = "Enterprise"; then EXPORT_METHOD_PLIST_PATH=${CODE_PATH}/ExportOptions/EnterpriseExportOptions.plist else EXPORT_METHOD_PLIST_PATH = ${CODE_PATH} / ExportOptions/DevelopmentExportOptions plist fi # refers to the ipa set output folder, if you have deleted after creation, If test -d ${IPA_PATH}; Then rm -rf ${IPA_PATH} mkdir -pv ${IPA_PATH} echo ${IPA_PATH} else mkdir -pv ${IPA_PATH} fi # "${CODE_PATH}" # run pod pod install --verbose --no-repo-update #mkdir -p build # "++++++++++++++++clean++++++++++++++++" xcodebuild clean -workspace ${APP_NAME}.xcworkspace -scheme ${APP_NAME} - configuration ${configuration} # app packaged into xcarchive format file echo "+ + + + + + + + + + + + + + + + + archive++ + + + + + + + + + + + + + + +" xcodebuild archive -workspace ${APP_NAME}.xcworkspace -scheme ${APP_NAME} -configuration ${configuration} -archivePath ${ARCHIVE_PATH} # will be packaged into xcarchive file format of ipa echo "+ + + + + + + + + + + + + + + + + ipa++ + + + + + + + + + + + + + + +" xcodebuild - exportArchive -archivePath ${ARCHIVE_PATH} -exportPath "${IPA_PATH}" -exportOptionsPlist ${EXPORT_METHOD_PLIST_PATH} -allowprovisioningupdates # delete project file # echo "+++++++++ delete project file +++++++++" # rm -rf $ARCHIVE_PATH # Path to upload result log file PGYERLOG_PATH="${IPA_PATH}/upload_pgyer_log" mkdir -p ${PGYERLOG_PATH} # IPA "echo" echo $file_path ="${IPA_PATH}/${IPA_NAME}. IPA "echo  curl -F "file=@${file_path}" -F "uKey=0ea4142136d51cbe5aaf94cdbf6aaeb1" -F "_api_key=16d3ff684c5576f9d9f6c958cf0a7300" https://upload.pgyer.com/apiv1/app/uploadCopy the code

Build (package upload)

Build immediately

Click Build Now to start building

Click build to view the status and console output

Jenkins packages a summary of common IPA errors

Problem 1. Pod command not found

When you run the Jenkins service on a non-OS X system, the configuration is slightly different using Mac nodes.

The solution

  • System Administration – System Configuration – Global Properties

Value: Enter echo $PATH in the terminal to copy the output.

Fault 2: The IPA package failed to be exported, causing an error:curl: (26) Failed to open/read local data from file/application

1. Check whether the IPA file is successfully packed in the file path. 2. View the path in the script file. The IPA name in the script is different from that in the packaged IPA file.Copy the code
The solution

Change the IPA name in the script to the display name of the application

Problem 3. Packaging error:Error: exportArchive: The data couldn't be read because it isn't in The correct format.

Solution 1

Xcode archive When exporting ipA, do not select Rebuild from Bitcode. The exported exportoptions. plist replaces the adhocexportOptions. plist in the project directory

Solution 2

You need to turn off the BitCode in Xcode and set it to No. You need to turn off the BitCode in project and targets

Problem 4. Packing is wrong:xcodebuild: error: 'APP.xcworkspace' does not exist

The solution
Choose Product > Scheme > Manage Schemes.
Share your scheme:
Copy the code

The Xcode Workspace File path may be incorrect

Question 5. Editor errorerror: /Users/plz/.jenkins/workspace/target_name/Pods/Target Support Files/Pods-HIGO/Pods-HIGO.release.xcconfig: unable to open file (in target "target_name" in project "target_name") (in target 'target_name' from project 'target_name')

The solution

Add the following command to the shell script

1. Sudo gem install cocoapods --pre 2Copy the code

Question 6. An editor errorThis project contains no schemes

The solution

We can not go to Jenkins project directory to modify Xcode project shared check, we should change the local development source code, and then commit to git remote repository, build again!!

Question 7. Edit error ` xcodebuild – exportArchive – archivePath/XXX. Xcarchive – exportOptionsPlist/Users/XXX/ExportOptions plist -allowProvisioningUpdates -exportPath ./

error: archive not found at path ‘/xxx.xcarchive’ Build step ‘Execute shell’ marked build as failure`

The solution

Script input error during script build. Procedure

Question 8. The editor reported an errorerror: archive not found at path '/Users/plz/Desktop/Jenkins/HIGO/Archive/HIGO_20210122-15-43-31.xcarchive'

A look at the log shows that pod Install was interrupted while executing and the imported tripartite library was not pulled down

The solution

Run pod update PLPlayerKit –no-repo-update before shell script pod install as prompted by the log

Refer to the article

Jenkins+ Github + FIR continuous integration of iOS project

IOS: Jenkins + XcodeBuild package IPA + Upload Dandelion