Recently, I set up a Jenkins script to automatically package the IOS installation package IPA of Flutter. I encountered some minor problems. Take Jenkins version 2.263 as an example to record the deployment service.

1. Install the Jenkins

Enter brew Install Jenkins in the Terminal command line to install the Jenkins service. If you see Hudson.WebAppMain$3#run: Jenkins is fully up and running, indicating that Jenkins has been successfully started. Open http://localhost:8080/ in the browser and you can see the Jenkins home page, as shown in the screenshot below:

2 Installing plug-ins

Description setter Plugin, GitHub Branch Source Plugin,GitLab Plugin,Keychains and GitHub Branch Source Plugin Provisioning Profiles Management,SSH Build Agents plugin,Timestamper,Upload to pgyer,Workspace Cleanup Plugin,Xcode Remember to start the Jenkins service once the plug-in is successfully installed.

3 Configure environment variables

Open Terminal, enter: vim. bash_profile and press Enter (if there is no bash_profile file, enter: touch.bash_profile). The screenshot is as follows:

After opening the bash_profile file, enter the letter I and press enter Terminal to change it into INSERT at the bottom to edit it. The screenshot of my configuration file (erase part is my computer name, which is also a directory file) is as follows:

After the configuration file is complete, press ESC to exit editing, and then press (semicolon). In Terminal, enter wq! Remember to press Enter and exit the vim command to complete the configuration (please learn the vim command by yourself if you are not familiar with it). The screenshot is as follows:

4 Configure the IOS development certificate and production certificate

Search for apple Developer certificate name :Mac Launcher – Keychain access – login. In the screenshot, the red circle above is the name of Apple Developer certificate, and the red circle below is the development certificate, production certificate, push certificate, as shown below:

Go to folder path /Users/ your computer name /Library/Keychains, due to Mac system problems, some systems show login.keychain, some systems show login.keychain-db. Keychain-db is displayed on my computer. Copy a copy of login.keychain-db and rename it login.keychain.

Jenkins home page – Systems Administration – Uncategorized, find Keychains and Provisioning Profiles “Management”, there is a “select file” button, Upload the login.keychain, remember to click “Upload” and restart Jenkins, screenshot below:

Once the file login.keychain is complete, continue back to itKeychains and Provisioning Profiles ManagementThe system starts to configure the IOS certificate. KeyChains, Filename is “login.keychain”,Password is the computer boot Password. Click Add Code Signing Identity, enter the name of Apple developer certificate in the Code Signing Identity, and configure the development certificate, production certificate, and push certificate in sequence. The detailed screenshots are as follows:

The Apple Developer certificate configuration is complete, then configure the certificate description file, and continue back toKeychains and Provisioning Profiles ManagementAt the bottom of the Provisioning Profiles page, find the Provisioning Profiles module,Provisioning Profiles Directory Path Path input to/Users/your computer name such as “XXX/Library/MobileDevice/Provisioning Profiles”, and click Save, click Save screenshots are as follows:

5 Building a Project

Jenkins home page – Create a new task, enter the task name (I’ll call it Demo_IOS), select “Build a free style software project “, and click” OK “.

Click “Add parameter” and select “Text parameter” for configuration. “BUILD_TYPE” indicates test debug or release version, and “GIT_BRANCH” indicates git branch address of project source code.

Source management configuration: The source code of my project was managed by Git,Branches to build was used by Jenkins to package and pull the specified Git Branches.

Build environment configuration: before “Keychain” is the name of the upload/Users/your computer name/Library/Keychains/login Keychain, “Code Signing Identity” is the IOS developers to prove, screenshots are as follows:

Install Brew Install Fastlane first. The specific script is as follows:

Security set – key – partition – list – S – tool: apple, apple: – “your computer login password” S – k ~ / Library/Keychains/login. The keychain

project_path=$(pwd)

flutter clean

flutter build ios –target lib/environment/main_${BUILD_TYPE}.dart   –release

cd $project_path/ios

Take the current time string to add to the end of the file

now=$(date +”%Y_%m_%d_%H:%M”)

# Specify the scheme name of the project

scheme=”Runner”

Specify the configuration name to package

configuration=”Release”

# Specify the output method to use for packaging, currently supporting app-Store, package, ad-hoc, Enterprise, Development, and developer-ID, the method parameter for XcodeBuild

  if [ $BUILD_TYPE == “release” ]

  then

      export_method=”ad-hoc”

 else

     export_method=”development”

  fi 

# specify the project address

workspace_path=”${project_path}/ios/Runner.xcodeproj”

# specify the output path

rm -rf “${project_path}/build/ios/ipa”

mkdir -p “${project_path}/build/ios/ipa”

output_path=”${project_path}/build/ios/ipa”

Output archive file address

archive_path=”output_path/store_{export_method}.xcarchive”

Output IPA address

ipa_path=”output_path/store_{BUILD_TYPE}_${GIT_BRANCH}.ipa”

Output IPA name

ipa_name=”store_${BUILD_TYPE}.ipa”

commit_msg=”$1″

Print the value of the set variable

echo “===workspace path: ${workspace_path}===”

echo “===workspace: ${WORKSPACE}===”

echo “===archive path: ${archive_path}===”

echo “===ipa path: ${ipa_path}===”

echo “===ipa_name: ${ipa_name}===”

echo “===export method: ${export_method}===”

echo “===commit msg: $1===”

# Clear an unprecedented build first

Fastlane gym –scheme scheme− Clean − Configuration {scheme} –clean –configuration Scheme – – clean – – configuration {configuration} – archive_path archivepath – – exportmethod {archive_path} – export_method Archivepath – – exportmethod {export_method} – output_directory outputpath – – outputname {output_path} – output_name Outputpath – – outputname {ipa_name}

Upload to pgyer with apiV1, register an account in advance on the dandelion platform, screenshot below:

Finally, click Build with Parameters to start building the project, scan the code to install after success. Screenshot below:

The ipA package packaged in the app-Store mode is bulky and cannot be installed on the Iphone. It can only be uploaded to the AppStore. Keep in mind these two points.