当前位置:网站首页>From scratch, use Jenkins to build and publish pipeline pipeline project
From scratch, use Jenkins to build and publish pipeline pipeline project
2022-07-04 08:31:00 【My hair is too heavy】
List of articles
One 、 Environment installation deployment
1. install JDK

2. Configure environment variables
C:\Program Files\Java\jdk1.8.0_152\bin

3. Install and activate IDEA



-javaagent:D:\IntelliJ IDEA\IntelliJ IDEA 2019.3.1\bin\jetbrains-agent.jar
4. structure web project






5. install tomcat The server




To configure IDEA, Enable it to recognize tomcat


6. install git, Turn on version control



7. Gitlab Warehouse building
hostnamectl set-hostname gitlab && su
# Install dependency packages
yum install -y policycoreutils openssh-server openssh-clients.x86_64 postfix
# start-up ssh Service and set startup
systemctl start sshd && systemctl enable sshd
# Set up postfix Boot from boot , And start the
systemctl start postfix && systemctl enable postfix
rpm -ivh gitlab-ce-12.4.2-ce.0.el6.x86_64.rpm
modify gitlab Access address and port , The default is 80, Let's change it to 82
vim /etc/gitlab/gitlab.rb
23 external_url 'http://192.168.8.20:82' # The access address is set to local IP Address
1112 nginx['listen_port'] = 82 # Monitor port changed to 82, The previous comments need to be cancelled
gitlab-ctl reconfigure
gitlab-ctl restart
http://192.168.8.20:82 visit Gitlab
Administrator changes root password , After changing the password , Log in

8. add group 、 Create user 、 Create project

Create user 


Add users to groups



With the just created zhangsan The user login , Then create a new project in the user group

9. Upload the test source code to Gitlab Warehouse







Two 、Jenkins install
Jenkins Need to rely on JDK, So install it first JDK1.8 , Installation directory is :/usr/lib/jvm
hostnamectl set-hostname jenkins && su
yum install java-1.8.0-openjdk* -y
rpm -ivh jenkins-2.277.4-1.1.noarch.rpm
vim /etc/sysconfig/jenkins
29 JENKINS_USER="root"
56 JENKINS_PORT="8888"
systemctl start jenkins
Open browser access http://192.168.8.19:8888
# obtain Jenkins Password
cat /var/lib/jenkins/secrets/initialAdminPassword


1. Modify the plug-in address
cd /var/lib/jenkins/updates
sed -i 's/http:\/\/updates.jenkins- ci.org\/download/https:\/\/mirrors.tuna.tsinghua.edu.cn\/jenkins/g' default.json && sed -i 's/http:\/\/www.google.com/https:\/\/www.baidu.com/g' default.json
https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json

2. Install the plug-ins required for the project
Restart after installation Jenkins
Chinese # translate
Role-based Authorization Strategy # management Jenkins User permissions
Credentials Binding # Voucher plug-in
Git # Use Git Tools to Gitlab Pull the source code of the project
Deploy to container # Deploy projects to remote Tomcat Inside
Maven Integration # structure Maven project
Pipeline # establish Pipeline project
3. Add credentials
stay Jenkins Installation on server Git Tools
yum install git -y
git --version

- Username with password



- SSH Key type
Use root Users generate public and private keys , stay /root/.ssh/ The directory holds the public and private keys
ssh-keygen -t rsa

Put the generated public key in Gitlab in


stay Jenkins Add credentials to , Configure private key 
- Create a project , Test the availability of credentials

Use the form of key pair to form success 

3、 ... and 、 Installation configuration Maven
1. Jenkins Server installation maven
tar zxvf apache-maven-3.6.2-bin.tar.gz
mkdir -p /opt/maven
mv apache-maven-3.6.2/* /opt/maven
vim /etc/profile # Configure environment variables , Add... At the end
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk
export MAVEN_HOME=/opt/maven
export PATH=$PATH:$JAVA_HOME/bin:$MAVEN_HOME/bin
source /etc/profile


2. To configure JDK and Maven

JDK1.8
/usr/lib/jvm/java-1.8.0-openjdk

maven3.6.2
/opt/maven

3. add to Jenkins Global variables

JAVA_HOME /usr/lib/jvm/java-1.8.0-openjdk
M2_HOME /opt/maven
PATH+EXTRA $M2_HOME/bin

4. modify Maven Configuration file for
- Change the local warehouse in the configuration file to :/root/repo/
mkdir /root/repo
vim /opt/maven/conf/settings.xml
54 <localRepository>/root/repo</localRepository>

- Add alicloud private server address
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>

5. test Maven Is the configuration successful?



You can see that the project is marked as war It's packed , representative maven Environment configuration successful
Four 、 Installation configuration Tomcat
1. install
yum install java-1.8.0-openjdk* -y
tar -xzf apache-tomcat-8.5.47.tar.gz
mkdir -p /opt/tomcat
mv /root/apache-tomcat-8.5.47/* /opt/tomcat /opt/tomcat/bin/startup.sh 2. To configure Tomcat User role permissions
vim /opt/tomcat/conf/tomcat-users.xml
<role rolename="tomcat"/>
<role rolename="role1"/>
<role rolename="manager-script"/>
<role rolename="manager-gui"/>
<role rolename="manager-status"/>
<role rolename="admin-gui"/>
<role rolename="admin-script"/>
<user username="tomcat" password="tomcat" roles="manager-gui,manager-script,tomcat,admin-gui,admin-script"/>

In order to be able to log in to Tomcat, You also need to modify the following configuration , Remote access is not allowed by default , Now you need to comment out
# Turn on Remote Access
vim /opt/tomcat/webapps/manager/META-INF/context.xml
<!--
<Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
-->

3. restart Tomcat, Access test
/opt/tomcat/bin/shutdown.sh
/opt/tomcat/bin/startup.sh


5、 ... and 、 structure Pipeline Assembly line project
Jenkins There are many types of Autobuild projects in , Commonly used :
Free style software project (FreeStyle Project)Maven project (Maven Project)
Assembly line project (Pipeline Project)
Groovy Pipeline Two kinds of grammar are supported :
Declarative( declarative )Scripted Pipeline( Scripted )
Pipeline There are also two ways to create :
Directly in Jenkins Of Web UI Input script in the interfaceBy creating a Jenkinsfile The script file is put into the source library of the project
It is generally recommended to use Jenkins Directly from source control (SCM) Directly loaded in Jenkinsfile Pipeline This method
1. Create a pipeline project


pipeline {
agent any
stages {
stage('pull code') {
steps {
echo 'Hello World'
}
}
stage('build project') {
steps {
echo 'Hello World'
}
}
stage('deploy item') {
steps {
echo 'Hello World'
}
}
}
}
Generate pull code 


Generate compiled build code


Generate deployment code ( add to tomcat Proof of )




Building a successful 


2. Pipeline Script from SCM
Because in Jenkins Of UI Interface writing Pipeline The code is inconvenient for script maintenance , And scripts are easy to lose , So you can put Pipeline The script is in the project ( Version control together )
Created in the project root directory Jenkinsfile file , Copy the script content into the file
Note here is to observe whether the code changes color , Probability of not recognizing , Cause the build to fail ~

Then on Jenkinsfile File submission code


To Gitlab Check whether the submission is successful on the warehouse

Reconfiguration web_demo_pipeline project


Yes IDEA Change the code on and resubmit 
Build complete 
visit Tomcat View publishing results , Here is the comparison between before and after


边栏推荐
- zabbix监控系统自定义监控内容
- Mouse over to change the transparency of web page image
- Flutter 集成 amap_flutter_location
- ES6 summary
- Famous blackmail software stops operation and releases decryption keys. Most hospital IOT devices have security vulnerabilities | global network security hotspot on February 14
- 一文了解數據异常值檢測方法
- [Chongqing Guangdong education] National Open University spring 2019 455 logistics practice reference questions
- Using the rate package for data mining
- What sparks can applet container technology collide with IOT
- Moher College phpmailer remote command execution vulnerability tracing
猜你喜欢

zabbix監控系統自定義監控內容

【Go基础】1 - Go Go Go

Sqli labs download, installation and reset of SQL injection test tool one of the solutions to the database error (# 0{main}throw in d:\software\phpstudy_pro\www\sqli labs-...)

Manjaro install wechat

What does range mean in PHP

Azure ad domain service (II) configure azure file share disk sharing for machines in the domain service

Call Baidu map to display the current position

User login function: simple but difficult

How to re enable local connection when the network of laptop is disabled

1. Getting started with QT
随机推荐
Conversion of yolov5 XML dataset to VOC dataset
Devops Practice Guide - reading notes (long text alarm)
AcWing 244. Enigmatic cow (tree array + binary search)
如何通过antd的upload控件,将图片以文件流的形式发送给服务器
2022 examination questions for safety managers of metal and nonmetal mines (underground mines) and examination papers for safety managers of metal and nonmetal mines (underground mines)
What does range mean in PHP
Group programming ladder race - exercise set l2-002 linked list de duplication
Display Chinese characters according to numbers
[BSP video tutorial] stm32h7 video tutorial phase 5: MDK topic, system introduction to MDK debugging, AC5, AC6 compilers, RTE development environment and the role of various configuration items (2022-
zabbix監控系統自定義監控內容
运动【跑步 01】一个程序员的半马挑战:跑前准备+跑中调整+跑后恢复(经验分享)
Flutter integrated amap_ flutter_ location
L1 regularization and L2 regularization
Application of isnull in database query
Email alarm configuration of ZABBIX monitoring system
Fault analysis | MySQL: unique key constraint failure
Redis sentinel mechanism
1. Qt入门
Div hidden in IE 67 shows blank problem IE 8 is normal
Sort by item from the list within the list - C #