当前位置:网站首页>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
边栏推荐
- FRP intranet penetration, reverse proxy
- Group programming ladder race - exercise set l1-006 continuity factor
- Azure ad domain service (II) configure azure file share disk sharing for machines in the domain service
- 猜数字游戏
- 墨者学院-phpMyAdmin后台文件包含分析溯源
- 根据数字显示中文汉字
- NewH3C——ACL
- Chrome is set to pure black
- How to solve the problem that computers often flash
- Private collection project practice sharing [Yugong series] February 2022 U3D full stack class 007 - production and setting skybox resources
猜你喜欢
【Go基础】1 - Go Go Go
墨者学院-phpMyAdmin后台文件包含分析溯源
Moher college phpMyAdmin background file contains analysis traceability
The second session of the question swiping and punching activity -- solving the switching problem with recursion as the background (I)
L1 regularization and L2 regularization
How to improve your system architecture?
Ecole bio rushes to the scientific innovation board: the annual revenue is 330million. Honghui fund and Temasek are shareholders
1. Getting started with QT
Email alarm configuration of ZABBIX monitoring system
Snipaste convenient screenshot software, which can be copied on the screen
随机推荐
Unity write word
ctfshow web255 web 256 web257
Use preg_ Match extracts the string into the array between: & | people PHP
[CV] Wu Enda machine learning course notes | Chapter 9
Fault analysis | MySQL: unique key constraint failure
L1 regularization and L2 regularization
FOC control
没有Kubernetes怎么玩Dapr?
DM database password policy and login restriction settings
C#实现一个万物皆可排序的队列
What if the wireless network connection of the laptop is unavailable
Learn nuxt js
Put a lantern on the website during the Lantern Festival
Openfeign service interface call
根据数字显示中文汉字
Moher College webmin unauthenticated remote code execution
Mouse over to change the transparency of web page image
Thesis learning -- time series similarity query method based on extreme point characteristics
Moher College phpmailer remote command execution vulnerability tracing
What does range mean in PHP