Know Jenkins

Continuous integration

Continuous Integration (CI) : Concept of role Each team is responsible for the development of various modules, modules, independent testing, can be used before all the modules together test will find a lot of problems, the solution is rework to modify the code, but may also exist problems So, often put all module integration test together, there is a problem can be found as soon as possible, This is called continuous integration. The purpose is to find the problems of the whole 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 Maven life cycle, integration of various plug-insAdvantages 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) : The version upgrade time of Internet projects is too long, and the feedback of users is not timely modified, which will fail to improve the user experience and cause serious loss of users. The small version is quickly iterated, the feedback information of users is constantly collected, and the new version can be delivered to users as soon as possible

2: Features iteration quickly, continuous release, no need to wait for a big release to be delivered to users

Continuous Deployment (CD) : Continuous Deployment (CD) is an automated deployment method that delivers software features frequently to speed up code delivery to feature rollout, ensuring that new features can be deployed to production and used in the first place

Jenkins profile

Jenkins is an open source CI&CD software designed to automate a variety of tasks including building, testing, and deploying Jenkins. Jenkins has excellent and notable features: 1: Continuous integration and Continuous delivery 2: Easy to install 3: Easy to configure 4: Plugins 5: Extensions 6: The official website of Distributed JenkinsJenkins’s official websiteJenkins User manual to help us use and learn Jenkins:Jenkins User Manual

Why we need Jenkins

As you can see in the figure above, many of the repetitive actions needed to be performed manually throughout the process from development to deliveryAs shown in the figure above, Jenkins was used to automate the cascading operation of the process

The goal of Jenkins

1: Risk reduction The integration is carried out multiple times a day, and the corresponding test is done, which is conducive to the inspection of defects

2: Reduce repetitive processes Fixed operations such as compilation, testing, packaging, deployment and so on must be done, and no part can be omitted. Using Jenkins and other continuous integration tools can transform the build process from manual to automated

3: generated at any time can be deployed software continuous integration can be released at any time can be deployed software, using continuous integration, can often have a few small changes to the source code, and will integrate these code and other code, there is a problem, the project team can immediately know that problems will be repaired immediately

If continuous integration is not adopted, problems may not be discovered until integration testing takes place prior to delivery, resulting in delayed release of the product

Jenkins installation

The following steps are required: 1: Install the JDK 2: Download Jenkins war package or directly install Jenkins 3: Run the Java -jar Jenkins. War -httpport =8080 4: Open the browser and go to the link: localhost:8080 5: For details on how to verify Jenkins, see installing Jenkins in the user manual on the official website

Jenkins for the first time

1: Run java-jar jenkins. war -httpport =8080, and the following page will be displayed, waiting for Jenkins to complete the preparation2: Unlock Jenkins to the specified file, copy the initial password, and continue3: Add initial plug-ins if the network is bad, it is not recommended to install a large number of plug-ins in the initial plug-ins. Select 0 to skip in “Select plug-ins to install” and operate through the later plug-in management4: Creates an administrator user5: global security configuration6: Plug-in management

Acceleration plug-in installation

2. In the update-center.json file, use the IDM to accelerate the multithreaded download of the plug-in HPI file, and install the multithreaded download tool offline: IDM. 6.35.11. Retail. CHS. Exe domestic plug-in source address:Jenkins – useful. Gitee. IO/update – cent…

Jenkins-CI

Jenkins’ core feature: Pipeline

Jenkins Pipeline is a set of plug-ins that integrate the implementation and implementation of continuous delivery into Jenkins, continuously deliver version control management based software to your users and consumers. Every operation of the development delivery process is integrated into the Pipeline. Every action in the process can be executed via Pipeline and CI can be done very easily through Jenkins UI:

Jenkins Java projects integrate global configuration

1: The global configuration page is displayed2: configure the JDK3: Integrates Maven4: Integrate Git

Build Java projects with Jenkins

1: Click new Item to enter the new task page2: Configure project name Here we select the first configurationEnter the description of the project3: Configure source path and branch4: Configure the Maven plug-in. Select the following under build4: Start building Click Build Now to Build the project immediatelyYou can see our build history belowClick on a build history and you’ll see something like the figure below, and click on the console output to see the build log

Work space on Jenkins

Click on the workspace to see the code we builtCheck whether the source code and compiled WAR package exist in the workspace on the right

Jenkins-CD

Preparing the Web container

To set the tomcat management account, configure the tomcat-users. XML file in tomcat/configAdd 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"/>
Copy the code

The Tomcat management page is displayed. If yes, the configuration is successful.

Integrated deployment plug-in

1: Download the Deploy to Container Plugin 2: Select the project to be deployed, click Configure on the left, and configure post-build Actions. A Select Deploy War/EAR to a Container b and configure deployment information1: Select the war package location relative to the workspace location 2: Enter the project access name 3: Enter the Tomcat account and password and select the configured account and password 4: Enter the Tomcat publishing address

Automatic deployment

Procedure: 1: Select a project in Jenkins to build2: View the WebApp directory in Tomcat. 3: Confirm that the project is loaded. 4: Enter the access address of the project in the browser

Jenkins configures the GitLab hook program

Jenkins in the operation

  1. Select the item that you want to configure
  2. Click Configure
  3. Triggers after selecting Build Triggers

6. Configure HOOKS in GitLab or Github:http://192.168.1.149:8080/jenkins/job/controller/build?token=jenkins Check whether Jenkins hook program is valid == Type:http://192.168.1.149:8080/jenkins/job/controller/build?token=jenkinsDuring normal development, you modify the code, use Git push to a remote Git repository or perform push operations in the IDE and watch Jekins respond: when a request comes in, the project is built immediately

Jenkins executes the shell to start the Java program

#! /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 &
Copy the code

When finished, build the project and check the execution history to see if the shell’s print statements and our JAR’s main function print statements appear

Jenkins CI/CD

DevOps

DevOps, based on a blend of the words development and operation, aims to shorten the system development lifecycle, where feature releases, bug fixes, and updates are tightly integrated

Similar to the concept of continuous delivery, DevOps promotes a culture of collaboration between development and operations, with a bias towards the building of a culture

Traditional team organization: 1: there is a disconnect between development and operations; 2: processes are divided and executed by different people; 3: high communication costs and repetitive workInternet team organization: 1: People with different skills in a team working towards a common software development goal; 2: Optimizing the cycle of the entire process

conclusion

After reading this article, I hope you can understand: 1: Continuous integration and continuous delivery 2: Jenkins’ goals and what can be done 3: Build, continuous integration, continuous deployment using Jenkins 4: The concept of DevOps