preface

During the development process, you are always asked by other colleagues (development, testing, production, etc.) to do temporary packages. It just so happens that you configured an automated packaging tool that uses Python commands locally, but it’s still unavoidable to store the code for the current branch and then switch the branch to be packaged on the local machine. Going back and forth can take a lot of time, not to mention a lot of time if you use manual packing.

So how to improve work efficiency?

Open up packaging to testers, product operations, etc., so they can always load the latest packages and use the tools. We just develop and deliver the code, let the test package, and let the product or operations review it. The best thing to do is to deploy the DevOps platform (do your own research if you don’t know), and the process after development is nothing to do with us, it’s all about getting out of work on time.

Jenkins installation

brew install jenkins
Copy the code

After installation, start Jenkins service or manually start Jenkins each time (generally, the first one is more convenient)

 #Start the Jenkins
 brew services start jenkins
 #Stop Jenkins 
 brew services stop jenkins
 #Restart the Jenkins
 brew services restart jenkins
 
 #Go straight to Jenkins.
jenkins
Copy the code

Open your browser, type localhost:8080, go to the relevant path to find the password and copy it in

Configuration package engineering

First check if you have a Git plug-in installed. If not, just install it in Plugin Manager.

Create a new packing empty project

To theSource Code ManagementEnter the GitLab HTTP address of your project and the branch you want to package. The second line is to configureCredentialsClick Add to use the default typeUsername with password, then enter your GitLab username and password.

Next configure the triggerBuild TriggersHere I am configuring a command trigger and daily timing package. Various other triggering conditions can also be configured. For example, if you want to configure gitLab push code to trigger, you need to go to GitLab to configure itapi tokenJenkins also has to configuregit lab connection.Gitlab+Jenkins builds continuous integration system

Then configureBuild EnvironmentIn this example, git commit logs are configured to fetch git commit logs, but fastlane is also used to fetch Git commit logs.

And the last step,BuildIt’s just written herefastlane ios agent_dev, which is essentially executing the Fastlane script.

Fastlane configuration

To explain why I’m using Fastlane here, some people on the Internet configure build commands or Xcode build scripts directly on Jenkins. I’ve tried that and it works, but the configuration process is tedious and easy to step into. So IN the end, I used Fastlane. I only needed the configuration file, and it was easy to migrate and modify it later. I always thought that whatever tool, the simpler the better.

Fastlane installation

Without further ado, let’s start by changing the Ruby source

$ gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/
$ gem sources -l
https://gems.ruby-china.com
#Make sure it's only gems.ruby-china.com
Copy the code

Install the fastlane

$ sudo gem install fastlane -NV
Copy the code

Fastlane configuration

CD to the project directory, and then fastlane init

Here is a good tool to recommend to youGo2Shell, after the installation is opened, infinderThere will be a smiley button, click can CD directly to the current directory, withiTermIt’s easier to use.

Here, select 4 (custom configuration). 2 and 3 are “TestFilght” and “App Store” configurations, so I don’t need to select it.

The bundle update command may get stuck, so you need to open GemFile in the project directory and modify the Ruby source. After saving, continue to execute the bundle update in the current directory.

# old #source "https://rubygems.org" # new source "https://gems.ruby-china.com"Copy the code

FastLane write

With all the preparation done, open the project directory and you’ll find a new FastLane folder with a Fastfile file. Package script can be configured inside, the following is my configuration, after modification can be used directly. To test the success of local packaging, perform fastlane in the current directory.

default_platform(:ios) platform :ios do desc "Description of what the lane does" before_all do Changelog_from_git_commits (# COMMIT Message range: [ENV [' GIT_PREVIOUS_SUCCESSFUL_COMMIT] | | "HEAD ^", "the HEAD"], # formatting, % s represents the commit message, % an representative submitted pretty names: "\n iOS \n - %s (%an)", # Ignore Merge message merge_commit_filtering: 'exclude_merges',) # faselane pod install operation targetName = "Backend" # project name cocoapods end  #-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - DEV configurationlane :agent_dev do|options| currentTime = Time.new.strftime("%Y-%m-%d %H: %m: %S") gym( scheme:"Backend_debug", configuration: "Release", #Release or debug clean:true, # clear workspace:"AgentBackend. Xcworkspace ", # project entry file name "xxx. workspace" export_method:"ad-hoc", # package such as the type of AD hoc or App Store output_directory: "/ Users/XXX/Downloads/Backend_DEV # {currentTime}", # packaged output path I write is time, Output_name :"Backend_DEV", # generated ipA filename export_xcargs: "- allowProvisioningUpdates") puts "start upload dandelion pgyer" (api_key: "b599c64357f6b8404c152a30caXXX," user_key: "819 c717f5bd0d3123e248a1e431xxx", update_description: lane_context [SharedValues: : FL_CHANGELOG]) puts "started uploading FIR" firim(firim_api_token: "e69b09d037ca9979007e545a2b67XX",app_changelog:lane_context[SharedValues::FL_CHANGELOG]) endCopy the code

Changelog_from_git_commits are attempts to retrieve git commits prior to packing, and they were retrieved and inserted as updates when they were uploaded to dandelions.

If you need pod install from cocoapods, you need to add a line of gem “Cocoapods” to the Gemfile mentioned above.

Xcodeproj =.xcWorkspace =.xcodeProj

Upload to dandelion or Fir

Here is the command to install the two plug-ins, and then go to the platform to find the corresponding key

Pgyer # install fir Fastlane add_plugin firimCopy the code

Inform relevant personnel

After the packaging is completed, relevant personnel need to be notified by email or enterprise wechat, dingding and other ways. I used to push to the enterprise wechat, which can be configured on Fastlane, but I directly configure The FIR of Webhook on dandelion, the same. As for Webhook, a robot can be added to an enterprise wechat or Dingding group, and then a Webhook will be generated.

conclusion

The above process is relatively quick and simple, and can be configured in a few hours at most. Of course, this is only a simple example, but you can also configure quite a lot of things, such as uploading to the store, etc. There may be a lot of problems during the whole process, most of them can be found on the Internet, if you can’t find it, you can leave a comment, I may have encountered.

Jenkins starts packing up the two errors that are most likely to be reported

Fastlane requires your locale to be set to UTF-8. warning

Export LANG= en_us.utF-8 export LC_ALL= en_US.utF-8 is set in the Jenkins environment configuration and in the.zshrc and.bash_porfile files of the local machine.

Fastlane: Command not found

This is usually caused by Jenkins not setting the correct PATH and typing it on the command line

echo $PATH
Copy the code

Record the output results in Jenkins system Management-System Settings, find Environment variables, fill PATH in key and value in value, and save the output results in the first step. As shown in the figure below