当前位置:网站首页>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


边栏推荐
- [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-
- DM8 uses different databases to archive and recover after multiple failures
- [CV] Wu Enda machine learning course notes | Chapter 9
- go-zero微服务实战系列(九、极致优化秒杀性能)
- WordPress get_ Users() returns all users with comparison queries - PHP
- Unity-Text上标平方表示形式+text判断文本是否为空
- [go basics] 2 - go basic sentences
- ctfshow web255 web 256 web257
- Basic operations of databases and tables ----- view data tables
- How to solve the problem that computers often flash
猜你喜欢
![[go basics] 2 - go basic sentences](/img/b1/961615b439d75679a3bb40a60f208d.png)
[go basics] 2 - go basic sentences

Fault analysis | MySQL: unique key constraint failure

What does range mean in PHP

Mouse over to change the transparency of web page image

DM8 uses different databases to archive and recover after multiple failures

Ecole bio rushes to the scientific innovation board: the annual revenue is 330million. Honghui fund and Temasek are shareholders

Question 49: how to quickly determine the impact of IO latency on MySQL performance

DM8 tablespace backup and recovery

【性能測試】一文讀懂Jmeter

1. Qt入门
随机推荐
C#实现一个万物皆可排序的队列
How to get bytes containing null terminators from a string- c#
团体程序设计天梯赛-练习集 L1-006 连续因子
Système de surveillance zabbix contenu de surveillance personnalisé
yolov5 xml数据集转换为VOC数据集
Show server status on Web page (on or off) - PHP
How to play dapr without kubernetes?
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-...)
Leetcode 23. Merge K ascending linked lists
DM database password policy and login restriction settings
Guanghetong's high-performance 4g/5g wireless module solution comprehensively promotes an efficient and low-carbon smart grid
If the array values match each other, shuffle again - PHP
[go basics] 1 - go go
Unity text superscript square representation +text judge whether the text is empty
Laravel page load problem connection reset - PHP
Private collection project practice sharing [Yugong series] February 2022 U3D full stack class 007 - production and setting skybox resources
A method for detecting outliers of data
Figure guessing game
Call Baidu map to display the current position
Div hidden in IE 67 shows blank problem IE 8 is normal