preface

This article is probably the most comprehensive introduction of Jenkins deployment solution on the Internet. For a long time, leaders have been trying to solve the problem of code submission and packaging, especially in small companies, the packaging process is chaotic, resulting in the online version and code repository git or SVN code inconsistency problem. Joining Jenkins’ camp, it is urgent to solve many outsourcing problems.

The research process

At the beginning, I kept installing Jenkins under Docker, rented ali’s host for a long time, conducted experiments with Ali container service, repeatedly created Docker containers and established multiple Jenkins nodes. It was found that it was complicated to configure various variables in containers, and various development environments were not easy to deploy quickly. Of course, Jenkins was not studied enough at the beginning. Then I switched to a Windows console with Java, Maven, and Android. After a bit of a bumpy ride, I finally got it done. However, I know that ios development and compilation must use the MAC system, and I wanted to add a Jenkins node to achieve ios compilation. When it was done, I suddenly changed my mind and instead of leaving two computers on, I would deploy the entire Jenkins on the MAC (we don’t have a c# project at the moment, after all). So, all the operations, all the environments I went over again. Now I will explain one by one how to achieve full Jenkins continuous integration in MAC, without c# of course, all the way down the road, I think it is not a matter, the process is similar.

rendering

Jenkins homepage


Build history

Install Jenkins

I personally prefer new things, so I recommend using the higher version, I used 2.61, the latest version is 2.75. Brew installation using MAC, terminal execution

brew install jenkinsCopy the code

After the installation is completed, the terminal can start by running Jenkins.

jenkinsCopy the code

Install xcode

This one is easy, just download the latest version from the appstore. After installation, I pulled the company’s project into Xcode and first made sure that the project was compiled on the local machine. Here, I logged in the APP developer account to download various certificates and release them.

Install the Android studio

You can download it here at www.android-studio.org/





Set up the





The SDK path

Install git

Because our company uses Git, if your company uses SVN, you just need to make sure that the git or SVN command can be typed out. I have an older version here, try to use the new one, I don’t want to change.

MAC :~ shaolei$git version Git version 2.11.0Copy the code

Install the source tree

This is a very useful Git visualization tool that will be covered in more detail later. This software is not required, just to facilitate project pulling, so you can skip this step.

Configuring Jenkins Environment

This is the crucial one, the core of this article

Configure the plug-in

Download the plugin

  1. Android Emulator Plugin
     Starts an Android emulator with given properties before a build, then shuts it down after.Copy the code
  2. build timeout plugin
     This plugin allows builds to be automatically terminated after the specified amount of time has elapsed.Copy the code
  3. Email Extension Plugin
     This plugin is a replacement for Jenkins's email publisher    Copy the code
  4. Gradle Plugin
     This plugin allows Jenkins to invoke Gradle build scripts directly.Copy the code
  5. Keychains and Provisioning Profiles Management
     This plugin integrates management of keychain and provisioning files for iOS and OSX projects.Copy the code
  6. Maven Integration plugin
     This plug-in provides, for better and forworse, a deep integration of Jenkins and Maven: Automatic triggers between projects depending on SNAPSHOTs, automated configuration of various Jenkins publishers (Junit, ...) .Copy the code
  7. Pipeline
     A suite of plugins that lets you orchestrate automation, simple or complex. See Pipeline as Code with Jenkins for more details.    Copy the code
  8. Pipeline: GitHub Groovy Libraries
     Allows Pipeline Grrovy libraries to be loaded on the fly from GitHub.Copy the code
  9. SSH Slaves plugin
     Allows to launch agents over SSH, using a Java implementation of the SSH protocol.Copy the code
  10. Subversion Plug-in

  11. Timestamper

     Adds timestamps to the Console OutputCopy the code
  12. Workspace Cleanup Plugin
     This plugin deletes the project workspace after a build is finished.Copy the code
  13. Xcode integration
     This plugin provides builders to build xcode projects, invoke agvtool and package .ipa filesCopy the code

Among them, Android Emulator Plugin and Gradle Plugin are required plug-ins for Android. Keychains and Provisioning Profiles Management, Pipeline and Xcode Integration are required plug-ins for ios compilation. Among them, Maven Integration Plugin and SSH Slaves Plugin are the required plug-ins of Maven project, and the other Email Extension plugin is to notify the specific submission code developer of the Email when the compilation fails

Configuring system Settings

System Settings






Increase the plan

The Android project job

Create an Android Job

Creating an Android project





Configure the project’s Git repository address





Configuring triggers





Configure compilation and email notification



Juejin. Cn/post / 684490…

Ios project job

And Android the same source code management and triggers are not introduced, please refer to Android, the same below.
















Juejin. Cn/post / 684490…

Java project job






Juejin. Cn/post / 684490…

cd ${WORKSPACE}
mvn clean
cd ${WORKSPACE}/******/src/main/resources/
echo ${BUILD_NUMBER} >ver.xmlCopy the code

Of course, several key variables are used here, which are specific to Jenkins. See the following for more variables:

CHANGE_AUTHOR
For a multibranch project corresponding to some kind of change request, this will be set to the username of the author of the proposed change, if supported; else unset.
CHANGE_AUTHOR_DISPLAY_NAME
For a multibranch project corresponding to some kind of change request, this will be set to the human name of the author, if supported; else unset.
CHANGE_AUTHOR_EMAIL
For a multibranch project corresponding to some kind of change request, this will be set to the email address of the author, if supported; else unset.
CHANGE_TARGET
For a multibranch project corresponding to some kind of change request, this will be set to the target or base branch to which the change could be merged, if supported; else unset.
BUILD_NUMBER
The current build number, such as "153"
BUILD_ID
The current build ID, identical to BUILD_NUMBER for builds created in1.597+, but a TIMESTAMP YYYY-MM-DD_HH-MM-SSforOlder builds.................................................................................... , etc.Copy the code

H5 project job

Here I use zip package, deployment use zip decompression to the specified directory.

cd ${WORKSPACE}
echo ${BUILD_NUMBER} >ver.txt
zip -r h5.zip ./ -x .git\* -x README.md -x .project -x .gitignore
cp ${WORKSPACE}/h5.zip /Volumes/***/H5/h5-${BUILD_NUMBER}.zipCopy the code

conclusion

This paper comprehensively explains the continuous inheritance scheme of Jenkins’ projects. Because there are too many pits involved in the environment, we hope to fill the pits by ourselves.