“This article has participated in the call for good writing activities, click to view: the back end, the big front end double track submission, 20,000 yuan prize pool waiting for you to challenge!”

If the profile

The case study and basic configuration for Jenkins’ Windows installation and deployment to Linux, described in the previous article, is 🏆 (don’t miss it!). 【CI/CD technical topics 】 “Jenkins Practical Deployment series” (1) Introduction to the whole process of Jenkins environment building + basic deployment configuration (Windows->Linux), next, will focus on the relevant Jenkins key functions, automatic deployment will be introduced, including automatic pull branches and other functions!

Technical Resource Recommendation

Jenkins Official Documentation (Chinese version)

Jenkins official website

Automatic timed build

Timed build syntax:

* * * * *
Copy the code
  • The first * indicates minutes. The value ranges from 0 to 59. If other values are not specified, each specified minute will be built

  • The second * indicates the hour. The value ranges from 0 to 23. If other values are not specified, it indicates that every minute of each specified hour will be built

  • The third * indicates the day of a month. The value ranges from 1 to 31. If other values are not specified, the system builds data every minute on that day of a month

  • The fourth * indicates the month. The value ranges from 1 to 12. If other values are not specified, the system builds data every minute in that month of a year

  • The fifth * indicates the day in a week. The value ranges from 0 to 7. Both 0 and 7 indicate Sunday

Common timed build examples:

  • Because the code of a project is generally stored in SVN/GIT, a SVN/GIT project usually has multiple project teams submitting the code, and each project team is composed of several people, each of whom is also constantly maintaining their own piece of code.

  • Therefore, for a company, SVN/GIT commit records tend to be very frequent. Because of this, Jenkins tends to perform automated builds on a daily basis. The following example is an example of a timed build that is commonly used in a day.

Build every 5 minutes

H/5 * * * *

Build every two hours

H H/2 * * *

Every day at noon before work time to build a

0, 12 * * *

Build it regularly every afternoon before leaving work

0, 18 * * *

Timed build location

Choose Configuration > Build Trigger, as shown below:

3. Build after other projects are built: the project is triggered when other projects are successfully built, failed, or unstable.

Poll SCM and Build Periodically to automate building projects;

  • Poll SCM: Periodically checks for source code changes (based on the version number of the SCM software), checks out the latest code if there is an update, and then performs the build action. Configuration as shown below:

Select “Poll SCM” in the build trigger

Build periodically

Poll SCM

The input fields are minute, hour, day, month, week, and no limit. I set automatic deployment at 8am every day *.

  • / 5 * * * * (Check source code changes every 5 minutes)
  • Periodically (it does not care if the source code changes) the project is constructed as follows:

H 2 * * * (must build source code at 2:00 every day)

Enter in Schedule

0 * * * *

  • The first parameter is minute. The value ranges from 0 to 59.
  • The second parameter is hour. The value ranges from 0 to 23.
  • The third parameter is day. The value of day ranges from 1 to 31.
  • The fourth parameter is month. The value ranges from 1 to 12.
  • The last parameter indicates Week. The value ranges from 0 to 7. Both 0 and 7 indicate Sunday.

So 0 * * * * represents the 0 th minute of every hour the build is executed.

A few final examples

  • Every 10 minutes in the first half hour of each hour

H(0-29)/10 * * * *

  • Every two hours and 45 minutes, starting at 9:45 a.m. and ending at 3:45 p.m. each day

45 9-16/2 * * 1-5

  • Every two hours, 9 am to 5 PM every weekday (maybe 10:38 am, 12:38 PM, 2:38 PM, 4:38 PM)

H H(9-16)/2 * * 1-5

  • Sometime between the 1st and 15th of each month (except December).

H H 1,15, 1-11 *

  • Every Thursday at 19:30

30, 19 * * 4

  • Every morning at eight o ‘clock

0, 8, * * *

  • Build at 8:12:18 every Sixth day of the week

H 8,12,18 * * 6,7

  • Build every hour, 1 to 5,8 to 23

H 8-23 * * 1-5

  • Build every two hours 1 to 5,8 to 23

H 8-23/2 * * 1-5

  • Build every 30 minutes, 1 to 5,8 to 23

H/30 8-23 * * 1-5

Jenkins automatically merges branches

When releasing a project through Jenkins, it may be necessary to merge branches. For example, when releasing a test environment, you need to merge the dev branch into the Test branch. In this case, Jenkins can automatically implement this.

Configure the build parameters

  • Source Files Directory after the project is built
  • Remove prefix Removes the prefix
  • Remote Directoty release directory
  • When Exec Command releases the command, TOMCAT will be restarted
#! /bin/bash tomcat_home=/usr/local/tomcat-8 SHUTDOWN=$tomcat_home/bin/shutdown.sh STARTTOMCAT=$tomcat_home/bin/startup.sh Echo "closed $tomcat_home" $SHUTDOWN # kill tomcat processes ps - ef | grep $path | grep Java | awk '{print $2}' | xargs kill 9 # delete the log file, $tomcat_home/logs/* -rf $tomcat_home/work/* -rf sleep 5 echo "$tomcat_home" #tail -f $tomcat_home/logs/ CATALina.outCopy the code