Jenkins automated build nanny-level tutorial (continuously updated)

1.Installation

1.1 Release Notes

Visit the jenkins official website https://www.jenkins.io/ and enter the homepage
jenkins official homepage
Click the [Download] button to enter the jenkins download interface
jenkins download interface
The left side shows the latest long-term support version, and the right side shows the latest testable version (may be unstable). It is recommended to use the latest long-term support version. Here I use 2.401.3

1.2 Environmental description

Use the virtual machine centos7 system and install it using docker-compose.

1.3 Description of necessary conditions for installation

The virtual machine is connected to the external network, and docker, docker-compose, jdk (17), maven (3.9.3), and git are installed. Please install these software yourself. It is relatively simple. If not, please contact Du Niang. The software is installed. Post-recommend verification

docker docker version

docker-compose docker-compose -v

jdk java -version

maven mvn -v

git git --version

Create the jenkins.yml build file in the /root directory of the virtual machine (centos7) system

version : '3.8'
services:
  jenkins:
    image: jenkins/jenkins:2.401.3-lts
    container_name: jenkins
    restart: always
    user: root
    ports:
      - "8888:8080"
      - "8089:50000"
    environment:
      - m=1024M
      - u=0
      - TZ=Asia/Shanghai
    volumes:
      - /usr/java/jdk17.0.8:/usr/java/jdk17.0.8
      - /usr/java/maven3.9.3:/usr/java/maven3.9.3
      - /usr/libexec/git-core:/usr/libexec/git-core
      - /root/jenkins/home:/var/jenkins_home
      - /etc/localtime:/etc/localtime
      - /root/repo:/root/repo

Configuration file description:
a. User must be specified as the root user, otherwise an error message will be reported during startup indicating that /var/jenkins_home has no access rights
b .You must specify the mapping relationship between the host and container paths of running environments such as jdk, maven, git, etc., and modify the installation path according to your actual installation path

1.4 Install and start

Execute the one-click startup command in the directory where jenkins.yml is located: docker-compose -f The path where jenkins.yml is located up -d

View the startup status: docker logs -f jenkins
Insert image description here
The content in the red box is the password for initial login. At this time, you can enter: virtual machine ip:8888 in the browser to access< /span> Click to start using Jenkins Go to homepage Click the [Save and Complete] button to enter the instance configuration interface, save and complete directly After the plug-in is installed, it will automatically enter the add administrator account interface. It is recommended to add Administrator account, do not use the admin account Click to enter the recommended plug-in installation interface and wait patiently for the installation to complete
Insert image description here
Enter the console password and click the Continue button. The software needs to load some necessary configurations. Please wait patiently for a while. After the loading is completed, you can enter the plug-in installation interface. Since you are not familiar with the software, it is recommended to choose [ Install recommended plug-ins]
Insert image description here

Insert image description here

Insert image description here
Insert image description here

Insert image description here

Insert image description here

2.Configuration

2.1 Chinese version (recommended configuration)

manage jenkins ->Plugins->installed plugins Enter local in the search box and find that the Chinese plug-in has been installed. Just restart jenkins
Insert image description here
Restart jenkins
Insert image description here
After the restart is complete, visit again and find that the menus are all in Chinese, and the Chinese version is completed
Insert image description here

2.2 System tool configuration

Mainly configure Publish Over SSH, build and package the jar and send it to the specified server and perform the operation operation
System Management->System Configuration
Global Key, password and other information configuration
Insert image description here
Specific remote server information configuration
Insert image description here
After the configuration is completed, you can click the [Test Configuration] button on the lower right to test. If it prompts "sucess" Description configuration successful
Insert image description here

2.3 Global tool configuration

maven settings.xml configuration, jdk, maven
a.maven settings.xml configuration
Insert image description here
b.jdk configuration (multiple can be configured, at least Configure one)
Insert image description here
c.git configuration (optional, you can use the default without configuring)
Insert image description here
d.maven configuration (can configure multiple, at least one)
Insert image description here

3.Use

3.1 Front-end vue project construction

Homepage->New task
Insert image description here
Enter the task name. You can use the copy function below to copy an existing task
Insert image description here
Click [OK] button to enter the task configuration interface
Insert image description here
Source code configuration: source code warehouse, access credentials, build branches, etc.
Insert image description here
Automated build configuration
Insert image description here
Build environment Settings
Insert image description here
Build command settings
Insert image description here
Remote server settings
Insert image description here
After the configuration is completed, click the [Apply] and [Save] buttons at the bottom. Jump to the build interface of the task, click the [Build Now] button to start the automatic build
Insert image description here
After starting the build, click the specific build version (#1, #2, #3... in the lower left corner) to view Construction situation
Insert image description here
When the bottom prompts success, the construction is successful. Try it now

3.2 Back-end springboot and springcloud project construction

Home page->Create a new task, enter the task name, and choose to build a maven project
Insert image description here
Enter the task name, and you can use the copy function below to copy an existing task Build environment configuration (this item does not need to be configured when building a back-end project): Build trigger configuration (no configuration required for manual build): Source code configuration (required) : General configuration (optional):
Insert image description here
Click the [OK] button to enter the task configuration interfaceSpecial instructions: What is set in the Root Pom file is the pom.xml of the maven project that needs to be built. If it is a maven multi-module project, you need to build the specified module. This needs to be set to the pom.xml of the specified module. For example, the structure of a maven multi-module project is that module a is the parent project, and project b and project c are under project a. If you need to build a c project, you need to set it here to [c/pom.xml] Goals and options configuration. Here you need to configure the maven packaging instructions. Clean first clears the jar and then executes the package packaging. The packaging process skips testing. The packaging environment is configured after -P. Subsequent configuration after packaging is completed (send jar to the server and run): Remote server Execution timing configuration Add remote server configuration Remote server directory and startup configuration: Then click [Apply], [Save] ] button to enter the task's build interface, click the [Build Now] button to start building the project After starting the build, click the specific build version (#1, #2, #3 in the lower left corner... ) Check the construction status When the bottom prompts "sucess", it means the construction is successful, try it now

Insert image description here

Insert image description here

Insert image description here

Insert image description here

Insert image description here





Insert image description here

Insert image description here

Insert image description here

Insert image description here

Insert image description here

4. Advanced applications

4.1jenkins distributed configuration and application (jenkins master-slave)

4.1.1 Background

In the scenario of many jobs, a single jenkins master executes code clone, compile, package and build at the same time. Its performance may be bottlenecked, which will affect the code deployment efficiency and affect the jenkins official provides jenkins distributed build, which disperses the running of many jobs. to different jenkins slave nodes, greatly improving the processing capabilities of parallel jobs.

Jenkins is distributed with multiple slave nodes. When there are many projects that need to be built, the slave will take on the workload of the master and create projects on the slave.

The environment of the slave should be consistent with that of the master. What software is installed on the master should be prepared the same on the slave, and the path should be consistent. The difference with the master is that there is no need to install Jenkins.

4.1.2 Architecture description

Insert image description here

4.1.3 Configuration

master 192.168.2.54 slave-01 192.168.2.51

The SSH Build Agents plugin must be installed on the Jenkins master node
Insert image description here
slave node configuration

Homepage—"System Management—"Node Management—"New Node Enter the new node interface, enter the node name, select the fixed node, and then click the [Create] button
Insert image description here
Insert image description here
Insert image description here
Insert image description here
Configuration After completion, click the [Save] button to complete the configuration of the Jenkins slave node.

Guess you like

Origin blog.csdn.net/yangfenggh/article/details/132244345