This is the sixth day of my participation in the First Challenge 2022

Jenkins is no stranger to developers. In the stage of software development and deployment, in order to achieve automation, Jenkins tools are preferred to complete the construction automation, which is an indispensable part of the development. This series of “Jenkins in Action” articles will introduce how Jenkins is used and put into play in practical work, and how it can help us work more efficiently. This is also a kind of summary of the work record, to share with you.

What is Jenkins

Jenkins is the leader in open source CI&CD software, providing over 1,000 plug-ins to support build, deployment, automation, and any project needs. And provides a very good operation interface, mainly for continuous, automatic build/test software projects, monitoring the operation of external tasks.

Often used in conjunction with version management tools and build tools. Common version control tools include SVN and GIT, and build tools include Maven, Ant, and Gradle.

Liverpoolfc.tv: Jenkins. IO

It has the following features:

  • Open source Java language development continuous integration tools, support CI, CD;

  • Easy installation, deployment and configuration: install through YUM, download war package and quickly implement installation and deployment through Docker container, which is convenient for web interface configuration and management;

  • Message notification and test report: Integrate RSS/E-mail to publish build results by RSS or generate JUnit/TestNG test reports by E-mail notification when the build is completed;

  • Distributed build: Jenkins support allows multiple computers to build/test together;

  • Document identification: Jenkins can track which jars are generated for which build, which version of jar is used for which build, etc.

  • Rich plugin support: With support for extension plugins, you can develop tools suitable for your team, such as Git, SVN, Maven, Docker, etc.

What is CI/CD

When Jenkins is used or referred to, the terms CI and CD are often heard. Here, it is necessary to give a separate introduction, so as to avoid confusion when mentioned in the following chapters.

1. CI (Continuous Integration)

Continuous Integration (CI) is a process that enables developers to integrate work into shared branches to enhance writing development.

Continuous integration emphasizes building and testing as soon as developers submit new code. Based on the test results, we can determine whether the new code and the original code are correctly integrated.

The process is shown below:

2. CD(Continuous delivery)

Continuous Delivery (CD) is based on Continuous integration to deploy the integrated code to the real operating environment (for example, the quasi-production environment).

For example, after we finish unit testing, we can deploy the code to a Staging environment that connects to the database for more tests. If the code is fine, you can continue to deploy manually to production. The diagram below shows the approximate working mode of CI/CD.

Three, Jenkins installation

1. Preparation

Below are Jenkins’ official recommendations for installing servers and software.

  • Machine requirements:
    • The recommended memory size is greater than 512 MB
    • 10 GB of hard disk space (for Jenkins and Docker images)
  • The following software needs to be installed:
    • Java 8 (either JRE or JDK)
    • Docker

What I will prepare here is to install in a CentOS 7.5 environment in non-Docker mode.

2. Install JDK1.8

If yes, skip this step.

Run the yum install -y java-1.8.0 command to install:

[root@xcbeyond ~]# yum install -y java-1.8.0
Copy the code

3. Install the Jenkins

1) perform wget – O/etc/yum. Repos. D/Jenkins. For Jenkins’ https://pkg.jenkins.io/redhat-stable/jenkins.repo. ‘.

[root@xcbeyond ~]# wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
[root@xcbeyond ~]# rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
Copy the code

If Jenkins key has been imported before, RPM –import will fail and can be ignored.

2) run yum install Jenkins to install Jenkins. During the installation, some RPM packages will be downloaded, which will be slow. Please wait for the installation to complete.

[root@xcbeyond ~]# yum install jenkins
Copy the code

3) Run systemctl start Jenkins to start Jenkins.

[root@xcbeyond ~]# systemctl start jenkins
Copy the code

4) perform ps aux | grep Jenkins command to check Jenkins startup state, and some parameters of startup.

/ root @ xcbeyond ~ # ps aux | grep Jenkins Jenkins 5535708 197740 6212 208 2.4? Ssl 19:33 0:41 /etc/alternatives/java -Dcom.sun.akuma.Daemon=daemonized -Djava.awt.headless=true -DJENKINS_HOME=/var/lib/jenkins -jar /usr/lib/jenkins/jenkins.war --logfile=/var/log/jenkins/jenkins.log --webroot=/var/cache/jenkins/war --daemon --httpPort=8080 --debug=5 --handlerCountMax=100 --handlerCountMaxIdle=20 root 6264 0.0 0.0 112720 980 PTS /0 S+ 19:33 0:00 grep --color=auto JenkinsCopy the code

By looking at the Jenkins launching state, can know the Jenkins’s default installation directory (JENKINS_HOME) is located in the/var/lib/Jenkins, logs in the/var/log/Jenkins Jenkins. Log

4. Initialize and configure Jenkins

So far, only the basic installation of Jenkins has been completed. In order to be able to use Jenkins, you still need to log in to the Web page for initialization and configuration.

1) First access, login.

Open the browser and access the IP address :8080, where IP is the real IP address of the Jenkins server.

Note: If IP :8080 cannot be accessed, possibly because port 8080 is not open to the public, you can turn off the firewall on Jenkins server.

[root@xcbeyond ~]# systemctl stop firewalld.service
Copy the code

Tip need to enter the administrator password on a page in the/var/lib/Jenkins found/secrets/initialAdminPassword password, enter the password, click the “continue” button, to initialize, wait a moment, will enter the page of “the new”.

2) Install the plug-in.

Here, I select “Install the recommended plug-in” and then select Jenkins plug-in, as shown in the picture below:

Then start to install the plug-in, wait patiently until it is finished, click “Continue”. (This process is slow, have a cup of tea, wait…)

(During the installation process, some plug-ins may fail to be installed. You can choose “retry” or “continue” because plug-ins can be installed one after another during the subsequent use.)

3) Create an administrator user and click “Save and Finish”.

4) Instance configuration.

Click “Save and Finish” to configure Jenkins URL.

At this point, Jenkins is installed and ready for normal use.

Reference article:

  1. jenkins.io/zh/doc/
  2. PKG. Jenkins. IO/redhat – stab…