Jenkins related knowledge of DevOps

Meet Jenkins

Continuous integration

Continuous integration (CI):
1: Conceptual role.
Each team is responsible for the development of each module. Although the independent test of the module can be passed, the integration of all the modules before the online test will find many problems. The solution is nothing more than code Rework and modify, but there may still be problems.
Then, all the modules are often integrated and tested, and problems can be found as soon as possible. This is continuous integration. The purpose is to find the problems of the overall operation of the project as soon as possible and solve them as soon as possible

2: Jenkins continuous integration
Jenkins can integrate git, maven, sonar, deployment plug-ins, etc., similar to the life cycle of maven, integrating various plug-ins
Insert picture description here
. Advantages of continuous integration:
1: easy to locate errors
2: easy to control the development process
3: easy to CodeReview
4: Easy to reduce unnecessary work

Continuous delivery

Continuous delivery (CD):
1: The role of the concept
The version upgrade time of the Internet project is too long, the user feedback is not modified in time, and the user experience cannot be improved. It will cause serious loss of users.
Use the small version to quickly iterate and continuously collect users' feedback . Feedback information, the fastest improvement and optimization, the new version can be delivered to users as soon as possible

2: Features
Rapid functional iteration, continuous release, no need to wait for a major version to be delivered to users

Continuous deployment (CD):
1: Conceptual role
Through automated deployment methods, software functions are frequently delivered to
speed up the speed of code submission to the function line, to ensure that new functions can be deployed to the production environment and used in the first time
Insert picture description here

Introduction to Jenkins

Insert picture description here
Jenkins is an open source CI&CD software that is used to automate various tasks, including building, testing and deploying software.
Jenkins has excellent and remarkable features:
1: Continuous integration and continuous delivery
2: Easy installation
3: Simple configuration
4: Plug-in
5 : Extension
6: Distributed
Jenkins official website, support Chinese: Jenkins official website
Jenkins user manual, to help us use and learn Jenkins: Jenkins user manual

Why you need Jenkins

Insert picture description here
As you can see in the above figure, from development to delivery, many repetitive actions need to be performed manually.
Insert picture description here
As shown in the above figure, Jenkins is used, and Jenkins automates the process in series operation.

Jenkins' goals

1: Reduce risk
. Perform multiple integrations in a day and do corresponding tests, which is conducive to checking for defects

2: Reduce repetitive processes
. Some fixed operations such as compilation, testing, packaging, deployment, etc. must be done, and no link can be omitted
. Using continuous integration tools such as Jenkins, the build link can be converted from manual completion to automatic completion.

3: Generate deployable software
at any time. Continuous integration can release deployable software at any time. With continuous integration, you can often make small changes to the source code, and integrate these codes with other codes, and problems arise. The project team You can know right away, the problem will be fixed the first time

If continuous integration is not used, then the problem may not be discovered until the integration test before delivery, resulting in delayed product release

Jenkins installation

Five steps are required:
1: Install JDK
2: Download the Jenkins war package or install Jenkins directly
3: Run the command: java –jar Jenkins.war –httpPort=8080
4: Open the browser and enter the link: localhost:8080
5: Follow the instructions to complete Verification The
specific operation steps can be viewed in the user manual on the official website: Install Jenkins

Using Jenkins for the first time

1: Run java –jar Jenkins.war –httpPort=8080, you will enter the following page, wait for the completion of Jenkins preparations
Insert picture description here
2: Unlock Jenkins
to the specified file, copy the initial password, and then continue
Insert picture description here
3: Attach the initial plug-in
if the network is not good, no It is recommended to install a large number of plug-ins in the initial plug-in, select 0 to skip in'Select plug-in to install', and operate through the following plug-in management
Insert picture description here
4: Create an administrator user
Insert picture description here
5: Global security configuration
Insert picture description here
6: Plug-in management
Insert picture description here

Speed ​​up plug-in installation

Speed ​​up plug-in installation method:
1: Jenkins management-plug-in management settings-upgrade site, enter the domestic plug-in installation source address
2.: in the update-center.json file, through IDM multi-threaded acceleration download plug-in hpi file, offline installation
multi-threaded Download tool: IDM.6.35.11.Retail.CHS.exe Domestic plug-in source address: https://jenkins-zh.gitee.io/update-center-mirror/tsinghua/update-center.json
Insert picture description here

Jenkins-CI

The core feature of Jenkins: Pipeline

Jenkins' Pipeline is a set of plug-ins that integrate the implementation and implementation of continuous delivery into Jenkins, and continuously deliver software based on version control management to your users and consumers
. Every operation of the development and delivery process is integrated into Pipeline. In, every operation in the process can be executed through the Pipeline, and
CI operations can be completed very easily through the Jenkins UI interface:
Insert picture description here

Jenkins java project integration global configuration

1: Enter the global configuration page
Insert picture description here
2: Configure JDK
Insert picture description here
3: Integrate Maven
Insert picture description here
Insert picture description here
4: Integrate Git
Insert picture description here

Use Jenkins to build a Java project

1: Click New Item to enter the new task page
Insert picture description here
2: Configure the project name
Here we choose the first configuration
Insert picture description here
Enter the description of the project
Insert picture description here
3: Configure the source code path and branch
Insert picture description here
4: Configure the Maven plug-
in Under Build, select the following content
Insert picture description here
Insert picture description here
4: Start to build
click Build Now builds the project immediately.
Insert picture description here
You can see our build history
Insert picture description here
below. Click on a build history to enter and see the following figure. Click the console output to see the build log
Insert picture description here

Workspace on Jenkins

Click
Insert picture description here
on the workspace to see the code we built. Workspace on the right to see if there is source code and compiled war package
Insert picture description here

Jenkins-CD

Prepare the web container

Set the management account of
tomcat : configure the tomcat-users.xml file under tomcat/config and
Insert picture description here
add the following configuration information:

<role rolename="manager"/>
<role rolename="manager-gui"/>
<role rolename="admin"/>
<role rolename="admin-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>
<user username="tomcatAdmin" password=123456" roles="admin-gui,admin,manager-gui,manager,manager- script,manager-jmx,manager-status"/>

Enter the tomcat management page, you can enter to indicate that the configuration is successful:
Insert picture description here

Integrated deployment plugin

1: Download the Deploy to container Plugin plugin
2: Select the deployed project, click the configure configuration on the left, and configure the Post-build Actions post-build operation
a drop-down box select Deploy war/ear to a container
b Configure the deployment information Insert picture description here
1: select The location of the war package, relative to the workspace.
2: Fill in the project access name
3: Fill in the tomcat account password, and then select the configured account password
4: Fill in the tomcat publishing address

Automatic deployment

Operation steps:
1: Select a project in Jenkins to build
Insert picture description here
2: View the webapp directory in tomcat
3: Confirm that the project has been loaded
4: Enter the access address of the project in the browser to access

Jenkins configuration GitLab hook program

Operations in Jenkins

  1. Select the item that needs to be configured
  2. Click configure configuration
  3. Select Build Triggers to trigger after buildInsert picture description here

Operation in GitLab
5. Fill in the key
6. Configure HOOKS in gitlab or github: http://192.168.1.149:8080/jenkins/job/controller/build?token=jenkins
Insert picture description here
Check whether the Jenkins hook program is valid
Enter in the browser: http://192.168.1.149:8080/jenkins/job/controller/build?token=jenkins
In the usual development process, modify the code, use git push to the remote Git warehouse
or execute it in the IDE Push operation
Observe Jekins' response actions: When a request comes, the project will be built immediately

Jenkins executes the shell to start the java program

Insert picture description here
Insert picture description here

#!/bin/bash
cd /usr/jarSh
echo "Execute shell Start"
sh stop.sh
sh replace.sh
echo "Execute shell Finish"
chmod 777 /usr/jarSh/startup.sh
BUILD_ID=dontKillMe nohup /usr/jarSh/startup.sh &

Build the project after completion, check the execution history, and see if there are print statements from the shell and statements printed by the main function of our jar package
Insert picture description here

Jenkins Complete CI / CD

Insert picture description here

DevOps

DevOps, based on a mixture of the two words development and operation, aims to shorten the life cycle of system development. In this process, the release of features, bug fixes and updates are all closely integrated.

DevOps is somewhat similar to the concept of continuous delivery. DevOps promotes a culture of collaboration between development and operation and maintenance, and tends to build a cultural atmosphere.

Traditional team organization:
1: Development and operation and maintenance are separated
2: Processes are divided and executed by different personnel
3: High communication costs, repetitive labor
Insert picture description here
Internet team organization:
1: People with different skills are in a team In, working for common software development goals
2: optimizing the cycle of the entire process
Insert picture description here

to sum up

After reading this article, I hope you can understand:
1: Continuous integration and continuous delivery
2: What is the goal of Jenkins and what it can do
3: Use JenKins to complete build, continuous integration, and continuous deployment
4: The concept of DevOps

Guess you like

Origin blog.csdn.net/qq_34365173/article/details/107359160