For a development, Xcode manual packaging is time-consuming and not very technical. The fundamental purpose of automated packaging is to save time and hand repetitive, untechnical tasks over to tools. Below, I introduce Jenkins’ automatic packaging scheme:

Mac installation Jenkins

Install via BREW

  • Install the latest version
brew install jenkins
Copy the code
  • Install the LTS version
brew install jenkins-lts
Copy the code

Download the PKG installation

Go to Jenkins’ official website and click on Downloads

Choose to download the stable version of LTS

Then select the version you want to install. More installation can reference the Jenkins’s official website: www.jenkins.io/zh/doc/book…

Installing the Java Environment

Since this Jenkins is still dependent on the Java environment, install it according to the version of Java that Jenkins is dependent on. First check whether the computer is configured with the Java environment

java -version
Copy the code

If not, can go to this address www.oracle.com/technetwork… Download the JDK. After the installation, run the Java -version command to view the installed version.

To configure the Java environment, type “which Java” on the terminal to output the installation path (used to configure environment variables). Open open ~/.bash_profile and type

/ / JDK installation path export JAVA_HOME = / Library/Java/JavaVirtualMachines/JDK - 16.0.2. JDK/Contents/Home export PATH=$JAVA_HOME/bin:$PATH:. export CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:.Copy the code

Finally enter source ~/.bash_profile to take effect.

Jenkins configuration

Once installed, type http://localhost:8080 into your browser to take you to the Jenkins launch page

Jenkins initialization

Find Jenkins in the installation directory of the computer, in Jenkins directory/Home/secrets/initialAdminPassword this directory, open the initialAdminPassword here and then copy out paste the password input box

Click to continue to this page, click on the recommended plug-in (default left option)

Then wait patiently for the plug-in to be installed

The next step is to create the first administrative account, follow the prompts step by step, and the initial configuration is complete.

Jenkins configuration plug-in

Next, you can configure the plugins Jenkins often use, choose System Management -> Plugins Management -> Optional Plugins. Then search for the following plug-ins to install:

  • GitLab Plugin and GitLab Hook Plugin
  • Xcode integration
  • DingTalk
  • upload-pgyer-plugin

These plug-ins can be searched directly click install, restart will take effect. However, we usually package with git submission records, so that other people know what package updated content, this plug-in is changelog Environment plugin, but this plug-in is not officially available, you need to compile and add.

Install the Changelog Environment Plugin

Since Jenkins did not have an official plugin to do this, he had to compile the plugin himself from the existing open source code. Download the plug-in source code: github.com/daniel-beck… .

Install Maven

Download address: maven.apache.org/download.cg…

Decompress to a directory

/ Users / * * * / apache maven -- 3.8.1Copy the code

Then add the Maven related environment to.bash_profile

Export M_HOME = / Users / * * * / apache maven - 3.8.1 export PATH = $PATH: $M_HOME/binCopy the code

Then execute source ~/.bash_profile for the configured environment to take effect

Enter MVN -v to check whether the configuration is successful

Compile source code to generate HPI

CD Go to changelog-environment-plugin-master and run the MVN verify command

After a long time, there will be a changelog-environment-plugin-master/target/ file changelog-environment.hpi. This is the plug-in we need.

Then upload the generated plug-in to Jenkins. You can finally find this in the installed plug-in

The use of Jenkins

Configure the nailing robot

Configure the pin robot in Dashboard -> Configuration. If want to custom message style, you can refer to the official plugin instructions: jenkinsci. Making. IO/dingtalk – pl…

Create a task

Set the General parameter

Set the stitching robot parameters

I am currently setting up the build successful notice after nailing group, notify the person is to fill in @ the phone Numbers of people, the custom content is the content of the notification panel display inside, these parameters are derived from dandelion App information interface, can view the information contained in’s official website: www.pgyer.com/doc/view/je…

This parameter is optional

This is where you can configure the selection of branches to build, packaged environments, compiled environments, and so on

Configure source code management

Open your project, copy the project link and fill in the Repository URL, then click Add to the right of the Credentials, mainly to pull the project for use, to display the Credentials shown below. There are two options: use the account password or use SSH

After adding, it will automatically check whether the credential you added is correct, and there will be an error message

Note: To configure SSH, check whether SSH has been configured. Run the ls -al ~/. SSH command on the terminal.

  1. If yes, the output is displayedId_rsa and id_rsa. PubIs displayed, the configuration is correct.
  2. If no, run the ssh-keygen -t rsa -c “[email protected]” command to generate id_rsa and id_rsa.pub files.

Enter vim ~/.ssh/id_rsa.pub directly on the terminal and copy the output to gitLab to configure SSH. Add it to the configuration credentials above.

Configure capturing Git commit information

【 - % 1 $s % 3 $s % 4 $s] MM/ddCopy the code

Adding a Build script

  • The first thing you need topod installUnder the project, add the script
Utf-8 export LANGUAGE= en_us.utf-8 export LC_ALL= en_us.utf-8 // Go to the project directory CD $WORKSPACE /usr/local/bin/pod install --verbose --no-repo-updateCopy the code
  • Add a build script
#! /bin/sh # Project name (required) workspace_name="" # Specify the scheme name of the project (required) scheme_name="" # specify how to package and compile: Debug, Release(required) build_configuration=${buildType} # method Bundle_identifier ="" # The following two parameters are only used when specifying Pofile files manually. If Xcode is used to automatically manage profiles, leave the mobileprovision file name blank. Double-click to install the. Mobileprovision file. Mandatory for manually managing profiles mobileprovision_NAME ="" if [${buildType} == "Debug"]; then build_configuration="Debug" method="development" mobileprovision_name="" else build_configuration="Release" Method = "AD - hoc mobileprovision_name =" "fi" echo "-- -- -- -- -- -- -- - the script configuration parameter check -- -- -- -- -- -- -- -- -- -- -" echo "workspace_name = ${workspace_name}" echo "scheme_name = ${scheme_name}" echo "build_configuration = ${build_configuration}" echo "method = ${method}" echo "bundle_identifier = ${bundle_identifier}" echo "mobileprovision_name = ${mobileprovision_name}" # = = = = = = = = = = script some fixed parameter definition (basic does not need to be modified) = = = = = = = = # # for the current script directory script_dir = "$WORKSPACE / $workspace_name" # project root directory Export_path ="$project_dir/Build" # Specify the output archive file path Export_ipa_path ="$export_path/$scheme_name.xcarchive Export_options_plist_path ="$project_dir/ exportoptions. plist" echo "-------- Check script parameters -----------" echo "project_dir = ${project_dir}" echo "export_path = ${export_path}" echo "export_archive_path = ${export_archive_path}" echo "export_ipa_path = ${export_ipa_path}" echo "export_options_plist_path = ${export_options_plist_path} "# = = = = = = = = = = = = = = = = = = = = = = = automatic packing part (no special cases need not modify) = = = = = = = = = = = = = = = = = = = = = = # echo "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --" echo "began to build the project" # CD into the project directory ${project_dir} # does not exist is created if output file directory [ -d "$export_path" ]; Xcodebuild clean -workspace ${workspace_name}. Xcworkspace -scheme ${scheme_name} Xcodebuild archive -workspace ${workspace_name}. Xcworkspace -scheme ${scheme_name} -configuration ${build_configuration} -archivePATH ${export_archive_path} # xcarchive If [-d "$export_archive_path"]; if [-d "$export_archive_path"]; Then echo "project build successful" else echo "project build failure" exit 1 fi echo "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --" echo If [-f ${export_options_plist_path}]; if [-f ${export_options_plist_path}] Then #echo "${export_optionS_plist_path} "rm -f ${export_options_plist_path} /usr/libexec/plistbuddy -c 'Add :provisioningProfiles:'${bundLE_identifier}' string '${mobileprovision_name}'' $export_options_plist_path /usr/libexec/PlistBuddy -c 'Add :method string '${method}'' $export_optionS_plist_path /usr/libexec/plistbuddy -c 'Add :compileBitcode bool NO' $export_optionS_plist_path // Export IPA packages xcodebuild -exportArchive -archivePath ${export_archive_path} -exportPath ${export_ipa_path} -exportOptionsPlist ${export_optionS_plist_path} -allowprovisioningupdates if [-f "$export_iPA_path /$scheme_name. Ipa "]; Then echo "${scheme_name}. Ipa package successful" open $export_path else echo "export ${scheme_name} If [-f "$export_optionS_plist_path "]; Then echo "${export_optionS_plist_path} Rm -f $export_optionS_plist_path fi # echo "${SECONDS}s" echo -e" echo"Copy the code

Configure the dandelion plug-in

“${SCM_CHANGELOG}” git commit information.

Jenkins Build Project

This is the optional parameter configured in the task. Select it and click Build

You can log in to Dandelion and see that the package uploaded successfully

This is a message to the spike group, which takes a long time due to the slow Internet speed when uploading dandelions. If want to custom message style, you can refer to the official plugin instructions: jenkinsci. Making. IO/dingtalk – pl…

This process must rely on the Xcode environment and the correct configuration of the certificate. It is more convenient to simply implement the packaging. In this way, whoever wants to package can open Jenkins and then Build. If you use Jenkins to configure the certificate, you need to download version 2.263.4 or earlier, the new version of Jenkins cannot upload the certificate and description file. Fastlane is more powerful and can create many lanes to do things, but you need to enter my developer account and password. So I prefer to use Xcode with scripts for packaging.

For other packing methods, please refer to the following article:

Juejin. Cn/post / 702801…

Juejin. Cn/post / 703096…