Jenkins installation and project configuration

foreword

This article will introduce the specific methods of Jenkins installation and project configuration, and add the part of Jenkins user management.

Some of the operation steps are directly given in the reference documents, and the corresponding steps can be completed through the reference documents.

Jenkins Chinese official website: Jenkins User Manual

1. Jenkins installation

Jenkins is written in Java language, and the installation package is a war package. Therefore, the operation and startup of Jenkins depends on the Java environment, and at the same time, it is free of installation.

1.1 Install JDK

Install jdk8 on linux

1.2 Install Maven (required for backend packaging)

It should be noted here that if you don't need to package the backend project through Jenkins , you don't need to install Maven.

Linux installation maven (detailed tutorial) - Fu Zongle - Blog Park (cnblogs.com)

1.3 Install Git

Install Git on Linux system

1.4 Install NodeJS (required for front-end packaging)

It should be noted here that if you don't need to package the front-end project through Jenkins , you don't need to install NodeJS.

How to install nodejs on Linux

1.5 Install Jenkins

1.5.1 Download Jenkins war package

The official website address is as follows: http://mirrors.jenkins.io/war-stable/latest/jenkins.war

1.5.2 Upload to Linux and run

Notice:

1. You should prepare a directory for storing Jenkins war packages and log files, for example: /usr/local/jenkins.

2. Which user you use to start Jenkins, Jenkins will create a hidden folder .jenkins in the user's home directory  . This folder takes up a lot of disk space, so you need to pay attention to the disk space mounting situation. At the same time, the directory can be changed, please refer to Baidu for details.

3. Not any user can start Jenkins. You should choose a user who has the directory permission of the project to start to avoid Linux permission problems when Jenkins updates the project.

cd /usr/local/jenkins
## 创建Jenkins运行日志文件
touch jenkins.log
## 启动Jenkins
nohup java -jar jenkins.war --httpPort=9999 > jenkins.log 2>&1

1.5.3 Complete the installation

Visit https://127.0.0.1:9999 in the browser to access jenkins, and then complete the unlocking.

After unlocking, choose to install the recommended Jenkins plugin and wait for the initialization to complete.

1.5.4 Set Chinese

Jenkins Chinese settings_zh__quan's blog-CSDN blog_jenkins Chinese

Two, Jenkins configuration

After you have installed Git, Maven, and NodeJS, if you want Jenkins to use them, you also need to install the corresponding plug-ins.

2.1 Download the necessary plugins

Click System Management --> Plug-in Management --> Optional Plug-ins, search and install.

2.1.1 Install Git

2.1.2 Install NodeJS

2.1.3 Install Maven

After the installation is complete, restart Jenkins.

Restart method: Jenkins access address, just splicing  /restart  .

2.2 Configure JDK, Git, etc.

Click System Management --> Global Tool Configuration.

 2.2.1 Configure JDK (fill in the JDK installation path)

 2.2.2 Configure Git (No need to fill in the Git address, Git commands are available globally)

  2.2.3 Configure Maven (fill in the Maven installation path)

  2.2.4 Configure NodeJS (fill in the NodeJS installation path)

3. Project configuration

3.1 Configure the front-end project

## 防止打包结束后进程被杀死
BUILD_ID=DONTKILLME
## 下载依赖
npm run install
## 打包
npm run build
## 删除原项目文件
rm -rf /home/data/tomcat-9.0.63/webapps/frontend
## 复制新打包的项目文件,注意当前所在的目录即为jenkins的工作目录,例如:/root/.jenkins/workspace/frontend。当然你也可以使用全路径。
cp -R dist /home/data/tomcat-9.0.63/webapps/frontend
## 重启tomcat
/home/data/tomcat-9.0.63/bin/shutdown.sh && /home/data/tomcat-9.0.63/bin/startup.sh

3.2 Configure the backend project

 Here you need to pay attention, if it is a single project, just clean install directly . If it is a multi-module project, you need to package the corresponding submodules, you can refer to the following command:

clean install -pl scs-nacos -am -amd -Pdev -Dmaven.test.skip=true

Indicates that only the scs-nacos submodule of the project and its dependent modules are packaged.

clean install -pl scs-biz/scs-biz-device -am -amd -Pdev -Dmaven.test.skip=true

Indicates that only the scs-biz -device submodule of the scs-biz submodule of the project and its dependent modules are packaged.

## 防止打包结束后进程被杀死
BUILD_ID=DONTKILLME
PID=`jps -l | grep -w "jenkins_test" | awk '{print $1}'`
if [ !$PID ]; then
	echo "=========== 项目未启动!"
else
    ## 停止项目
	kill -9 $PID
fi
sleep 1
## 复制,并替换jar文件
cp /root/.jenkins/workspace/backend/target/backend.jar /home/jenkins/backend.jar
## 重启项目
nohup java -jar backend.jar > backend.log 2>&1 &

 3.3 Start the project

4. User rights management

4.1 User Management

4.1.1 Jenkins user list

In the Jenkins user list, you can see all users (jenkins users, git users with commit records).

4.1.2 User Management

Jenkins users can only be managed in the System Management --> Manage User module.

4.2 Rights Management

4.2.1 Download permission control plug-in

Jenkins' own permission control granularity is too large to adapt to fine-grained permission management. Therefore, we pass

 Role-based Authorization Strategy plug-in for permission control.

4.2.2 Use permission control plug-in

Modify the authorization policy to use Role-Based management authorization. 

4.2.3 Create roles and configure permissions

4.2.4 Assign roles to users

Guess you like

Origin blog.csdn.net/qq_41057885/article/details/125417246