1. JENKINS is what

Jenkins is a self-contained, open source automation server that can be used to automate a variety of tasks related to building, testing, delivering, or deploying software.

Jenkins can be installed via the native system package, Docker, or even run independently by any machine with a Java runtime environment (JRE) installed

2. Install Jenkins on centos

Three ways

  • Install via Docker
  • Runs in Tomcat via Jenkins. War
  • Install using YUM

2.1 Installation using Docker

  • Create a Jenkins file and modify the file permissions
mkdir -p /usr/local/atom.hu/jenkins
chown -R 1000:1000 /usr/loca/atom.hu/jenkins
Copy the code
  • Pull the mirror
docker pull jenkins
Copy the code
  • Boot image
docker run -p 8080:8080 -p 50000:50000 --name jenkins --privileged=true -v /usr/local/atom.hu/jenkins/:/var/jenkins_home -d jenkins
Copy the code
  • Make a little wait

  • Access the directory to view the password

[root@localhost secrets]# cat initialAdminPassword 
9ca7368042fe45be8b693ab43e7797d1
Copy the code

2.2 Installation by way of Jenkins. War

Download the Jenkins war pack from the Jenkins website

You can right-click to copy the software address and use the wget command to download it

wget http://mirrors.jenkins.io/war-stable/latest/jenkins.war
Copy the code

After downloading, put the project into the Webapps folder in Tomcat

2.3 Installing Jenkins using YUM

Obtain the software installation source

sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
Copy the code
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
Copy the code

Install Jenkins

yum -y install jenkins
Copy the code

Start Jenkins after installation is complete

systemctl start jenkins
Copy the code

Through the experiment of the three methods, each method is explored. Finally, the installation method of YUM is selected, which is the most troublesome installation method, but relatively reliable. Although the installation method of Docker is simple, it will encounter many software environment problems. The jenkins.war method was relatively simple, but encountered many problems. Finally, we gave up and adopted the most primitive and troublesome method

3.0 Prerequisites for Automated Deployment using Jenkins

To ensure that the subsequent configuration can proceed smoothly, some preliminary preparations are required

Modify the Jenkins configuration file

Open the Jenkins configuration file
vim /etc/sysconfig/jenkins
# change $JENKINS_USER to root
$JENKINS_USER="root"
Copy the code

Modify Jenkins related folder user permissions

chown -R root:root /var/lib/jenkins
chown -R root:root /var/cache/jenkins
chown -R root:root /var/log/jenkins
Copy the code

Restart the Jenkins service and check whether the user running Jenkins has been switched to root

# Reboot Jenkins (if Jenkins is installed in another way, reboot Jenkins slightly differently)
systemctl restart jenkins
# Check Jenkins process owning user
ps -ef | grep jenkins
# If user root is displayed, the modification is complete
Copy the code

At this point, the preliminary preparation work is finished and we can start the automatic deployment of Jenkins

4.0 Install plugins in Jenkins

In Jenkins, it is recommended for beginners to install the recommended plug-in directly, then set the administrator password, and enter the main interface, remember not to forget the password, although there are solutions, but it is better to remember the password

Install the necessary Jenkins plugins

Git Parameter Plug-In

In the subsequent automatic deployment, we need to set different branches and package different branches through parameters, which requires the support of this plug-in

Maven Integration plugin

When deploying the Spring Boot project, we need to create the Maven project. After installing the plug-in, there is no option to build a Maven project at project creation time without the plug-in

Publish Over SSH

Publish Over SSH

Note that when filling in the host Ip, if two machines belong to the same operator, it is important to fill in the internal Ip as much as possible

5.0 Add a supporting environment to the server

  1. Installing OpenJDK 1.8 Jenkins requires openJDK dependencies to run

The official story

You will need to explicitly install a Java runtime environment, because Oracle’s Java RPMs are incorrect and fail to register as providing a java dependency. Thus, adding an explicit dependency requirement on Java would force installation of the OpenJDK JVM.

Yum install Java -- 1.8.0 comes with itsCopy the code
  1. Install git
yum install git
Copy the code
  1. After node is installed, front-end project requirements will be deployed
Download the installation packageWget HTTP: / / https://nodejs.org/dist/v10.15.3/node-v10.15.3-linux-x64.tar.xz# decompressionTar -xvf node-v10.15.3-linux-x64.tar.xz -c./# connect the node command and NPM Settings to /usr/bin
ln -s ./node /usr/bin/node
ln -s ./npm /usr/bin/npm

Then you can use both commands anywhere else
Copy the code
  1. The installationmavenAnd, in/etc/profileIn the configuration

6.0 System Configuration

In the Global Configuration tool, configure the JDK, Maven, Git, and Node installation paths

7.0 Automated deployment of the front-end VUE project

In deployment scenarios, the webpack is packaged on machine A and the packed files are sent to the specified folder on machine B for access through the Nginx agent

  1. Create a free-style software project

2. Fill in the project description

  1. Choose to parameterize the build process and then choose different branches for packaging

  1. Choose a different version control tool either SVN or Git, but here git is used

  1. Select in the build environmentSend files or execute commands over SSH after the build runs

The configuration here is, after the local build is complete, what files do we need to send to the target host, to the target host, and what commands do we need to execute

cd /home/project/web/test  
tar -zxvf dist.tar.gz
rm -rf dist.tar.gz
Copy the code

/home/project/web/test is the directory configured for the target host nginx

  1. Select in buildExecute Shell

    And configure the commands to execute at build time

cnpm i &&
rm -rf dist && 
npm run build && 
cd dist&& 
tar -zcvf dist.tar.gz *
Copy the code

Click Save, and you’re done setting up your front-end project

8.0 Automatically Deploying the Spring Boot Project

  1. Create a New task and create a Maven project

  1. Fill in the project description and configure parameters to build

  1. Configure source code management

  1. Configure the BUILD environment SSH Server

BUILD_ID=DONTKILLME
source /etc/profile;
cd /home/project/java/test&&

pid=`ps -ef | grep 'the name of the jar | grep -v grep | awk '{print $2}'`
if [ -n "$pid" ]
then
   kill9 -$pid
fiJava-jar lK-truck-mendery-webfront-1.0.0-snapshot. jar > nohup.log &Copy the code

Pay attention to the point

  1. shellNeed to add beforeBUILD_ID=DONTKILLMEOtherwise, when Jenkins created the Java process, he would exit and kill the project he created before
  2. Need to be added earliersource /etc/profileOr it might appearjavaCommand can’t be found

The Springboot project is now complete

9.0 What should I do if I forget my password after setting it

  1. Go to Jenkins’ profile
cd /var/lib/jenkins/users
vim config.xml
Copy the code

#jbcrypt:$2a$10$DdaWzN64JgUtLdvxWIflcuQu2fgrrMSAMabF5TSrGK5nXitqK9ZMS
Copy the code

After replacement, restart Jenkins

systemctl restart jenkins
Copy the code

The login password will change to 1111111