Introduction to using Jenkins continuous integration

Blog address: http://www.moonxy.com

I. Introduction

Continuous integration (CI) refers to integrating code into the trunk frequently (multiple times a day).

The purpose of continuous integration is to allow products to iterate quickly while maintaining high quality. Its core measure is that the code must pass automated tests before being integrated into the trunk. As long as one test case fails, it cannot be integrated.

Jenkins is a continuous integration tool developed based on Java, which is used to monitor continuous and repetitive work. The download address is: https://bitnami.com/stack/jenkins/installer , which provides installation packages for Windows, Linux and OS X platforms. The easiest way is to use the provided war package to start directly. The download address is: http://mirrors.jenkins-ci.org/ . At this time, you must ensure that jdk has been installed in the system, preferably jdk1.5 or above.

2. Initialize the Jenkins plugin and administrator user

After downloading the jenkins.war package, switch to the download directory under cmd, and then execute the following command:

java -jar jenkins.war

In this way, Jenkins starts to start, and its war package comes with a Jetty server. When Jenkins is started for the first time, for security reasons, Jenkins will automatically generate a random installation password. Note the password output from the console and copy it. Enter the address in your browser:

http://localhost:8080/

When you start jenkins for the first time, if you find that it has been stuck on the startup interface, it will prompt: Jenkins is starting, please wait...

You can press Ctrl + C to force the end of the startup, and then execute the above command again, and find that it will continue to start, or you can modify the configuration file, because your network may be restricted, as follows:

Enter the working directory of jenkins, the default is: C:\Users\Administrator\.jenkins

Open hudson.model.UpdateCenter.xml and replace http://updates.jenkins-ci.org/update-center.json with http://mirror.xmission.com/jenkins/updates/update-center.json, or If it doesn't work, find the default.json in the updates directory and change all the Google addresses in it to Baidu's, that is, replace http://www.google.com/ with http://www.baidu.com/.

2.1 Enter the following page and enter the password that appears above

Enter the following page for the first time after startup

2.2 After entering the page for choosing to install plug-ins, you can choose to install plug-ins recommended by the community or custom installation, and choose the former here

Generally, at least the following plugins need to be installed:

Git/Subversion、SSH、Publish Over SSH、Maven 等。

2.3 Create an administrator user

After filling in the account information, go to the completion page:

The installation is complete.

3. Configure the Jenkins build tool

After logging in to Jenkins for the first time with an administrator account, you need to set the build tool and JDK version you want to use in "System Management" -> "Global Tool Configuration" .

3.1 Enter the main interface of jenkins

3.2 Enter the global tool configuration page

Click  "System Management" -> "Global Tool Configuration"

After entering, configure the build tools

3.3 Configuring Maven

If Maven is already installed on the machine, provide the specific installation path in the Maven_HOME input box. Otherwise, you can choose the desired maven version and let Jenkins download maven automatically for you.

3.4 Configure JDK

Similarly, if the JDK has been installed on the machine, provide the specific installation path in the JAVA_HOME input box. Otherwise, you can choose the desired JDK version and let Jenkins download the JDK for you automatically.

3.5 Configuring Git

If you haven't installed Git, Subversion (SVN) or CVS plugins for Jenkins before, you can install them in "Administration" -> "Manage Plugins" .

4. Construction work

Build jobs are the heart of the Jenkins build process.

4.1 Click to create a new task to enter the creation project type selection page

If you find that there is no "build a maven project" item, you need to install the Maven Integration plugin , as follows:

4.2 Enter the detailed page of the build job

4.3 Source code management

Choose the source code management method according to the actual situation of your project:

4.4 Building triggers

There are 5 parameters, which represent:

MINUTE:Minutes within the hour(0-59)

HOUR:The hour of the day(0-23)

DOM:The day of the month(1-31)

MONTH:The month(1-12)

DOW:The day of the week(0-7)where 0 and 7 are sunday

Regular placement:

0 * * * * Execute every hour

0 1 * * * Execute once every day at 1:00 am. This configuration setting is suitable for executing some smoking test cases

The first parameter: min, 0-59

The second parameter: hour: 0-23

The third parameter: day: 0-31

Fourth parameter: month: 1-12

The fifth parameter: week: 0-7 (0 and 7 represent Sunday)

Difference between "Poll SCM" and "Build periodically" in Jenkins

Poll SCM : Regularly check the source code changes (according to the version number of the SCM software), if there is an update, checkout the latest code, and then execute the build action, the configuration is as follows:

*/5 * * * * (check source code changes every 5 minutes)

Build periodically : The project is built periodically (it does not care whether the source code changes), the configuration is as follows:

0 2 * * * (source code must be built at 2:00 every day)

4.5 Build

In "Build", the default project root directory's Root POM, ie pom.xml. If pom.xml is not in the root directory, fill in the subdirectory, eg cloud/pom.xml.

If "None" is selected in the source code management, click "Advanced..." here to customize the project address in the workspace, as follows:

Save the build job above:

5. Construction

After the job is built, the build process can be executed.

5.1 How the build is performed

 The first: Click the small triangle to the right of the task name, then click "Build Now"

The second: trigger the build automatically according to the "schedule" set in the "build trigger"

5.2 Build Results

The first column is "Last Build Status Display", which is a circular icon, generally divided into four types:

blue: build successfully;

Yellow: Not sure, the build may be successful, but contains errors;

red: build failed;

Gray: The project was never built, or disabled;

If it shows blue as above, it means the build is successful.

Note: The time to manually trigger the build does not affect the time of the automatically scheduled build.

5.3 View console output

You can view the console output of a successful build:

If the build fails, you can get specific error information by viewing the console output of the build failure, which is convenient for debugging

Click to view the error message, as follows:

 

The second column is the "Compile Barometer" as follows:

If you see that your project has become cloudy or raining, it means that your project is not stable, and you need to find the cause and solve the problem.

5.4 Deployment

If you want to deploy the built war package, you can fill in the shell command in Post Steps and deploy it directly with the script.

Another way is to create another build project and trigger the deployment manually.

Either way, it is to ensure that compilation and deployment are done through a continuous integration server, not a development machine.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325216088&siteId=291194637