2018.4.17 Update: Resolve the PKG installation permission issue on MAC
Fastlane command not found The Jenkins home directory on MAC
Writing in the front
Blog, Gold Digger, Jane’s book
Recently, when making a new project, I often find that there are many small bugs that need to be changed, which requires repackaging. Even if a small project is compiled, packaged and exported, and then uploaded to the test platform, it takes more than ten minutes to get off. Originally, I was looking for a script to auto-pack, but I found several things were not ideal, so I decided to focus on Jenkins + Fastlane
Jenkins is for management, Fastlane is enough if you just need to pack
This article is mainly about my own potholes, and most of them are from Jenkins. If you are interested, you can read on
The current environment
The name of the | version |
---|---|
macOS | 10.13.4 |
Xcode | 9.3 |
ruby | 2.4.0 |
fastlane | 2.91.0 |
Use the Fastlane
First, let’s talk about Fastlane. After all, Jenkins is in continuous management, and I believe many of you just want to automate fast compilation and packaging without waiting for a long time
The preparatory work
-
Use RVM to manage the Ruby environment. MacOS has a built-in Ruby environment. RVM /scripts/ RVM. Close the terminal and run RVM -v to see if it works. If command is not found, there is a problem. Specific situation needs specific analysis or Google
-
After installing Ruby, run “Which Ruby” to see if Ruby is managed by RVM
If the display is/Users/XXXXXX /. RVM/rubieslast/ruby – 2.4.0 / bin/ruby that is ok
- After installing fastlane, execute the install command
gem install fastlane -NV
At this point, we are ready to use Fastlane automation for packaging
Ready to pack
- CD Go to the project main directory
- perform
fastlane init
I chose manual configuration here - perform
fastlane add_plugin pgyer
Install the dandelion plugin
Edit Fastfile
# This file contains the fastlane.tools configuration
# You can find the documentation at https://docs.fastlane.tools
#
# For a list of all available actions, check out
#
# https://docs.fastlane.tools/actions
#
# Uncomment the line if you want fastlane to automatically update itself
# update_fastlane
default_platform(:ios)
platform :ios do
desc "Upload the beta version to Dandelion."
desc "Build a local version"
lane :topgyer do|option|
# Automatically add builds
# increment_build_number
Automatic certificate generation
#cert
Generate configuration files automatically
#sigh(force: true)// I use manual configuration to disable this. If you need to turn it on automatically
# GYM configuration, packaged output.
#fastlane gym --export_method ad-hoc
#fastlane gym --export_method enterprise
#fastlane gym --export_method app-store
scheme_name = "Your scheme name"
Get version and build version numbers
version = get_info_plist_value(path: "./#{scheme_name}/Info.plist", key: "CFBundleShortVersionString")
build = get_info_plist_value(path: "./#{scheme_name}/Info.plist", key: "CFBundleVersion")
# export path
output_directory = "./build"
# export name
output_name = "#{scheme_name}_#{version}_#{build}_#{option[:desc]}_#{Time.now.strftime('%Y%m%d%H%M%S')}.ipa"
gym(
export_method: "ad-hoc".I'm using ad-hoc
export_xcargs: "-allowProvisioningUpdates",
export_options:{
provisioningProfiles: {
"cn.com.kkk"= >"iPhone Distribution: kkk. (77777XXRRR)"
}
},
scheme: scheme_name,
clean: true,
output_directory: output_directory,
output_name: output_name
)
pgyer(api_key: "11111122222233333444444", user_key: "111122233344455555", update_description: "#{option[:desc]}")
end
end
Copy the code
Go back to the project project home directory and perform fastlane Topgyer DESC: update
Once compiled, it automatically uploads to dandelion
Jenkins on pit
Jenkins on the Mac is a big hole. You’re tired of trying to build through multiple installation methods, sometimes github doesn’t pull up code, sometimes Fastlane Command isn’t found, or you get a bunch of Ruby errors.
Finally, I tried all kinds of methods and finally got something
PKG installation
First let’s talk about the most frustrating PKG installation
Jenkins download the macOS version of LTS, which is conveniently a.pkg file, and install it.
You will find that the Jenkins directory is installed in the default /Users/Shared/ Jenkins directory, which is outside of your own user directory.
So…
Do not install using PKG...
2018.4.17 update
Note that you do not use the Shared user for installation (which is fine).
Disable the share user to prevent permission issues
Once the installation is complete, you will find that the key is also in the user directory
If you forget to check it, you’ll notice that the location of the key is in the shared/ Jenkins directory. Ok, delete the Jenkins directory from the Settings, delete the Jenkins directory from the shared folder, go back to the Finder, go to the Jenkins folder, double-click jenkins.jar
If you go back to localhost:8080, you can also see that the key address is back in the user directory
Next comes the normal plug-in and language installation.
Since RVM is used natively to manage Ruby, there are also a lot of pits, and these errors occur during builds.
I found a lot of methods, probably because of Ruby’s problem, adding global variables, still not working
Turns out, it’s pretty simple… One plug-in. Search for RVM in plug-in management
After r the installation is complete, select the Ruby version of RVM in the build environment configured for your project.
Now you can have fun building.
Command line installation
brew install jenkins
Backend implementation nohup Java jar/usr/local/Cellar/Jenkins/version number/libexec/Jenkins. War – httpPort = 8080 &
Open a new terminal and run open /Library/LaunchDaemons to create a new plist file
<? xml version="1.0" encoding="UTF-8"? > <! DOCTYPE plist PUBLIC"- / / / / DTD PLIST Apple 1.0 / / EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>StandardOutPath</key>
<string>/var/log/jenkins/jenkins.log</string>
<key>StandardErrorPath</key>
<string>/var/log/jenkins/jenkins.log</string>
<key>EnvironmentVariables</key>
<dict>
<key>JENKINS_HOME</key>
<string>/Users/leon/Documents/FuckingJenkins/Jenkins/Home</string>
</dict>
<key>GroupName</key>
<string>daemon</string>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>org.jenkins-ci</string>
<key>ProgramArguments</key>
<array>
<string>/bin/bash</string>
<string>/Library/Application Support/Jenkins/jenkins-runner.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>UserName</key>
<string>jenkins</string>
<key>SessionCreate</key>
<true/>
</dict>
</plist>
Copy the code
Then change the permissions plist sudo chown root: wheel/Library/LaunchDaemons/org. Jenkins – ci. Plist
Finally start Jenkins sudo launchctl load/Library/LaunchDaemons/org. Jenkins – ci. Plist
Back to localhost: 8080
Enter the password to enter the plug-in installation page.
After the installation is complete, go to the plug-in management to install a Chinese
Configure Chinese
The next step is to create the project normally.
You can directly fill in the password of the hosting platform account, or use sshkey
Here you can simply execute the Fastlane command
That’s enough for now.
Click Build Now, view the console, and all the logs will be printed.
Just wait for success
Afterword.
Step on the pit several times for the INSTALLATION of PKG has not given up, back and forth to reinstall several times. Finally gave up. Or old honest practical JAR
Reference article:
https://www.jianshu.com/p/dc6f3fea7aa9 https://www.jianshu.com/p/3b4a131653e0