One, foreword

I have been involved in the development of front-end projects. Different from the iOS workflow, the front-end only needs to combine the feature branch code into a specified branch before providing QA with a test. The QA team then builds and deploys the project using Jenkins tools. I’ve heard of Jenkins in my previous exploration of automated packaging for iOS, but never got to know him. This time, I take this opportunity to explore Jenkins from the iOS project I am best at.

2. Install Jenkins

**Jenkins** relies on the Java environment, so make sure your system has Java installed before installing Jenkins

  • Install Java terminal input command, if not recognized. The Java JDK is not installed
java --version
Copy the code

If it is not installed or the version is too early, you can download it from the following link. Note Select the Java JDK version to download according to your computer’s system

  • Install Jenkins
brew install jenkins
Copy the code

There are two pits to mention

  1. The version of BREW that installs Jenkins is not the latest version. This will result in some necessary Jenkins plugins not being installed. Solution: Uninstall and reinstall HomeBrew
  2. Always stuck on updating after brew solution: do not close the current terminal window, open a new one. And type the brew command again
  • Enable Jenkins Service
brew services start jenkins
Copy the code

After the first service is successfully enabled, type http://localhost:8080 into your browser and a page will appear asking you to enter Jenkins’ initial password

  • Obtain Jenkins initial password
defaults write com.apple.finder AppleShowAllFiles YES
vi /Users/jackey/.jenkins/secrets/initialAdminPassword
Copy the code

Enter the obtained initial password and restart Jenkins

brew services restart jenkins
Copy the code

Enter http://localhost:8080 again to go to the configuration page. Click to install the suggested plug-in and wait patiently for the plug-in installation process (it takes a long time).

If a plug-in fails to be installed, view the failure log. The problem I had was that the Jenkins version was too low, so some plugins wouldn’t install. The brew version is too low

  • Create an administrator account. After the plug-in is successfully installed, the following page is displayed

    After filling in all items as required, click save and you can use them normallyJenkinsthe

  • Turn off/restart Jenkins by URL
http://localhost:8080/restart
http://localhost:8080/exit
Copy the code

Iii. Configure the iOS project in Jenkins

  • Create a new Item and create a task. After you enter a task name, select the first item: Freestyle Project
  • Configuration is the General term
  • Source code management item
  • CocoaPods/Carthage dependency configuration items

Choose Build -> Add Build Configuration ->Execute Shell. Fill in the dependent Pod/Carthage command

There are two caveats here

  1. directlypod install --verbose --no-repo-updateComplains,pod: command not foundSolution: The export statement sets the console locale to UTF-8 to avoid Podfile opening errors.
  2. Adding a Pod Install script to a build uses the bar on the left to the first of the build items
  • Xcode -general Build Settings configuration
  • Xcode – Code signing configuration
  • Xcode -os X Keychain options configuration
  • Xcode-Advanced Xcode build options configuration
  • Add package and upload dandelion script add build step -Execute Shell. Enter the following script
# project name
APP_NAME="XLLJenkinsDemo"
If the certificate is automatically selected, set to "iPhone Developer"
CODE_SIGN_DEVELOPER="iPhone Developer"
# info. Plist path
project_infoplist_path=". /${APP_NAME}/Info.plist"

Get the version number
bundleShortVersion=$(/usr/libexec/PlistBuddy -c "print CFBundleShortVersionString" "${project_infoplist_path}")

# build value
bundleVersion=$(/usr/libexec/PlistBuddy -c "print CFBundleVersion" "${project_infoplist_path}")

DATE="$(date +%Y%m%d)"
IPANAME="${APP_NAME}_V${bundleShortVersion}_${DATE}.ipa"

# IpA file path to upload
IPA_PATH="$HOME/${IPANAME}"
echo ${IPA_PATH}
#echo "${IPA_PATH}">> text.txt

# Integration has Cocopods usage
echo "=================clean================="
xcodebuild -workspace "${APP_NAME}.xcworkspace" -scheme "${APP_NAME}"  -configuration 'Release' clean

echo "+++++++++++++++++build+++++++++++++++++"
xcodebuild -workspace "${APP_NAME}.xcworkspace" -scheme "${APP_NAME}" -sdk iphoneos -configuration 'Release' CODE_SIGN_IDENTITY="${CODE_SIGN_DEVELOPER}" SYMROOT='$(PWD)'

xcrun -sdk iphoneos PackageApplication "./Release-iphoneos/${APP_NAME}.app" -o ~/"${IPANAME}"


# Upload to dandelion
# user Key on dandelion
uKey="..."
# API Key on dandelion
apiKey="..."
Git git git git git git git git
MSG=`git log -1 --pretty=%B`
# IpA file path to upload
echo $IPA_PATH
 
Execute upload to dandelion command
echo "++++++++++++++upload+++++++++++++"
curl -F "file=@${IPA_PATH}" -F "uKey=${uKey}" -F "_api_key=${apiKey}" -F "buildUpdateDescription=${MSG}" http://www.pgyer.com/apiv2/app/upload
Copy the code

Iv. Project construction

  • Click Build Now to see the Build progress in Build History. We can click on the progress bar to enter live build details
  • In details, click console Output to view the build logs
  • If Build Success is found in the last few lines of the log, the project is successfully built.
  • If the following information is found at the end of the log, the dandelion is successfully uploaded

When you build here, there are all sorts of errors that can cause a build to fail at first. Troubleshoot the fault according to the log error information.

  • Don’t worry about the dense information in the log. Generally, a global search for ERROR: or just look at the last dozen or twenty lines of the log to read the key information.The general isProject configurationorSignature file and configuration certificateThe problem of

###### this is just a summary of a particular error I encountered after running the xcrun script: xcrun: error: Unable to find utility “PackageApplication”, not a developer tool or in PATH unable to find Utility “PackageApplication”, not a developer tool or in PATH The PackageApplication is missing in the new version of Xcode (note: The PackageApplication was deprecated in previous versions and removed in 8.3).

  1. Take an old version of Xcode and copy it into the following directory
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/
Copy the code
  1. Run the following two commands
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer/
chmod +x > /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/PackageApplication
Copy the code

Attach PackageApplication download address: pan.baidu.com/s/1jHJF2Lo source: www.jianshu.com/p/c83483289…

Five, other points of attention

If the project uses Pod and Carthage to manage dependencies on third-party libraries, make sure that Carthage and Pod are installed. And pod Setup is executed, otherwise the build will fail as well.

Jenkins workspace path to/Users/XXX /. Jenkins/workspace /, friends can regularly to clean, or according to the work location problem in engineering.

At present, the iOS project uses Gitlab’s own Runner to automate packaging. Later, we plan to configure the project with Jenkins, so that the iOS project can be uniformly constructed, processed and packaged by QA staff just like the front-end project.

Next, we will study a wave of front-end Jenkins configuration process and principle, please look forward to…