当前位置:网站首页>Jenkins continuous integration operation
Jenkins continuous integration operation
2022-06-13 00:59:00 【Xiao Bai】
Catalog
Normal user password credentials
Jenkins structure Maven Project test
Jenkins relation JDK and Maven
jenkins structure Maven project
Jenkins Credential management
Credentials can be used to store database passwords that need ciphertext protection 、Gitlab Password information 、Docker Private warehouse password, etc , In order to wenkins It can interact with these third-party applications . To be in venkins Use the credential management feature , Need to install credentials Binding plug-in unit ( The recommended plug-ins are installed by default ).
Click the user name in the upper right corner -> The credentials -> Click global -> Add the credentials

Common credential types :
Username with password: User name and password .
SSH Username with private key: Use ssH User and key .
Secret file: Text files that need to be kept secret , When using Jenkins The file will be copied to a temporary directory , Set a variable to the file , When the build is finished , The copy of secret file It will be deleted .
secret text: Need to save an encrypted text string , Like a nailing robot or Github Of api token.
certificate: By uploading the certificate file .
In order to make Jenkins Support from the Gitlab Pull source code , Need to install Git Plug in and in linux Installation on system Git Tools .( Previously installed )
Normal user password credentials
1) Create credentials Click the user name drop-down to select credentials ->Jenkins overall situation -> Add the credentials Type selection “Username with password”, Input Gitlab Username and password ( zhangsan(gitlab Your account and password )/12345678), Description input gitlab-auth-password Click on " determine ".
2) Test if credentials are available
Create a Freestyle project : newly build Item -> The name of the task (test01) Freestyle Project -> determine Source code management : choice Git,
Repository URL: http://192.168.37.103:85/devops_group/web_demo.git( Can be obtained from gitlab Use Http clone ),Credentials Drop down to select gitlab-auth-password, Click save .
Click on Bulid Now Begin to build , Looking at the console output, you can see that the build was successful , The built package will be generated on the server /var/lib/jenkins/workspace/testo1 Directory .
[[email protected] /var/lib/jenkins]# cd workspace/test01
[[email protected] /var/lib/jenkins/workspace/test01]# ls
pom.xml src web_demo.imlssH Key type
1) stay Jenkins On the server root Users generate secret free public and private keys
ssh-keygen -t rsa2) Put the generated public key in Gitlab in
Get the contents of the public key
cat /root/.ssh/id_rsa.pubWith root The account login Gitlab -> Click the avatar drop-down to select settings ->SSH Copy the contents of the public key file just now , Click add key

3) stay Jenkins Add credentials to , Configure private key
Get the contents of the private key
cat /root/.ssh/id rsaClick the user name drop-down to select credentials -> Jenkins overall situation -> Add the credentials Type selection
“SSH Username with private key", Description input gitlab-auth-ssh,Username Enter the user name to generate the private key root,Private Key Next choice Enter directly, Copy all the contents of the private key file just generated Click on " determine ”.


4) Test if credentials are available
Create a FreeStyle project : newly build Item-> The name of the task (test02)Freestyle Project-> determine Source code management : choice Git,
Repository URL: [email protected]:devops_group/web_demo.git Can be obtained from Gitlab Use ssH clone ),
Credentials Drop down to select gitlab-autH--ssh, Click save . Try to build the project , If the code can be pulled normally , Represents that the credential configuration was successful !

[[email protected] /var/lib/jenkins/workspace/test02/src/main/webapp]# cat index.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title> Demo project home page </title>
</head>
<body>
If you see this page , On behalf of the successful deployment of the project !
</body>
</html>Jenkins structure Maven Project test
stay jenkins Installation on server Maven To compile and package projects
cd /opt
[[email protected] /opt]# tar -zxf apache-maven-3.6.2-bin.tar.gz
[[email protected] /opt]# mv apache-maven-3.6.2 /usr/local/maven
[[email protected] /opt]# cd /usr/local/maven/
[[email protected] /usr/local/maven]# ls
bin boot conf lib LICENSE NOTICE README.txt
[[email protected] /usr/local/maven]# cd bin/
[[email protected]enkins /usr/local/maven/bin]# ls
m2.conf mvn mvn.cmd mvnDebug mvnDebug.cmd mvnyjp
[[email protected] /usr/local/maven/bin]# vim /etc/profile
.....-
export MAVEN_HOME=/usr/local/maven
export PATH=$MAVEN_HOME/bin:${JAVA_HOME}/bin:${JRE_HOME}/bin:$PATH
[[email protected] /usr/local/maven/bin]# source /etc/profile
[[email protected] /usr/local/maven/bin]# mvn -v
Apache Maven 3.6.2 (40f52333136460af0dc0d7232c0dc0bcf0d9e117; 2019-08-27T16:06:16+01:00)
Maven home: /usr/local/maven
Java version: 1.8.0_171, vendor: Oracle Corporation, runtime: /usr/local/jdk1.8.0_171/jre
Default locale: en_GB, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-693.el7.x86_64", arch: "amd64", family: "unix"Jenkins relation JDK and Maven
Manage Jenkins ->Global Tool configuration Click Add JDK, Alias input jdk1.8,
Uncheck the Install automatically,JAVA_HONE Input /usr/loca1/jdk1.8.0_171

Click Add Maven,Name Input maven3, Uncheck the Install automaticaily,MAVEN_HOME Sail in /usr/local/maven Click on " application " and " preservation ".

add to Jenkins Global variables ,
Give Way Jenkins Able to identify JDK and Maven Environment command
Manage Jenkins -> Configure system -> Global properties , Check Environment variables The key value pair list is added :
key JAVA_HOME, value /usr/local/jdk1.8.0_171
key M2_HOME , value /usr/ local/ maven
key PATH+EXTRA , value $M2_HOME/bin


modify Maven Of settings. xml
mkdir / root/repo # Create a local warehouse Directory
<!-- Change the local warehouse to /root/repo-->
55 <localRepository>/root/repo</localRepository>
<!-- Add alicloud private server address -->
154 <mirror>
155 <id>alimaven</id>
156 <mirrorOf>central</mirrorOf>
157 <name>aliyun maven</name>
158 <url>https://maven.aliyun.com/repository/public</url>
159 </mirror>
160 </mirrors># test Maven Is the configuration successful?
In the local pom clean install once
[[email protected] /var/lib/jenkins/workspace/mvn-demo1]# mvn clean
[[email protected] /var/lib/jenkins/workspace/mvn-demo1]# mvn installClick item test02-> Set up -> structure -> Add build steps ->Execute shell Input
mvn clean package # Empty the existing building elements ( plug-in unit 、 Dependency package, etc target file ),

And then pack it Click save To build again , If you can type the project into war package , representative maven Environment configuration successful .

tomcat install and configure
Start another server and install tomcat
install tomcat 9.0.16
[[email protected] web_demo]# cd /opt
[[email protected] opt]# ls
apache-tomcat-9.0.16.tar.gz rh
jdk-8u171-linux-x64.tar.gz
[[email protected] opt]# tar zxvf jdk-8u171-linux-x64.tar.gz -C /usr/local/
vim /etc/profile
....
export JAVA_HOME=/usr/local/jdk1.8.0_171
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:${JRE_HOME}/bin:$PATH
source /etc/profile
[[email protected] opt]# tar zxvf apache-tomcat-9.0.16.tar.gz
[[email protected] opt]# mv /opt/apache-tomcat-9.0.16/ /usr/local/tomcat
/usr/local/tomcat/bin/startup.sh ## Turn on tomcatTo configure tomcat User role permissions
By default Tomcat There are no user role permissions configured Verification method : Browser accessible http://192.168.37.108:8080, Click on Managing Tomcat Next Of manager webapp , Find back 403 page . But then Jenkins Deploy the project to Tomcat The server , Need to use Tomcat For remote deployment , So modify tomcat Following configuration , Add users and permissions
[[email protected] opt]# vim /usr/local/tomcat/conf/tomcat-users.xml
43 --> ## add to tomcat User role permissions , All specified user passwords are tomcat, And grant permission
44 <role rolename="tomcat"/>
45 <role rolename="role1"/>
46 <role rolename="manager-script"/>
47 <role rolename="manager-gui"/>
48 <role rolename="manager-status"/>
49 <role rolename="admin-gui"/>
50 <role rolename="admin-script"/> 51 <user username="tomcat" password="tomcat" roles="manager-gui,ma nager-script,tomcat,admin-gui,admin-script"/>
52 </tomcat-users>
[[email protected] opt]# vim /usr/local/tomcat/webapps/manager/META-INF/context.xml
19 <!-- ## Comment out value To configure
20 <Valve className="org.apache.catalina.valves.RemoteAddrValve"
21 allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
22 -->
restart tomcat
/usr/local/tomcat/bin/shutdown.sh
/usr/local/tomcat/bin/startup.sh
Revisit :http://192.168.37.108:8080/mananger/html , Enter the account and password tomcat You can login successfully
jenkins structure Maven project
● Free style software project (Freestyle Project )
You can build projects in many different languages ,Jenkins Build type provided by default
●Maven project (Maven Project)
Specifically for java Linguistic Maven Project to build , In the build Maven The project will be more convenient
● Assembly line project (Pipeline Project)
Write the build process in code , Very flexible Each type of build can actually be done --- What kind of build process and results , It's just the way it works 、 Flexibility and so on , In actual development, you can choose according to your own needs and habits
Free style project building
Project integration process : Pull the code -> compile -> pack -> Deploy
Pull the code
newly build item -> The name of the task (web_ demo_ freestyle) FreeStyle Project -> determine
Source code management : choice Git, Repository URL: [email protected]:devops_group/web_demo.git Credentials" Drop down to select gitlab-auth-ssh, Click save Click on Build Now, Try to build the project
Compile the package
To configure -> structure -> Add build steps -> Execute Shell, Enter the following command . echo" Start compiling and packaging ” mvn clean package echo " Compilation and packaging are over " Click on Build Now, Try to build the project
Deployment project
Deploy projects to remote Tomcat Inside
1) install Deploy to container plug-in unit
Jenkins It cannot be remotely deployed to Tomcat The function of , Need to install Deploy to container Plug-in implementation : Manage Jenkins -> Management plug-in - Optional plug-ins -> Search for Deploy to container The plug-in can be installed directly
2) Add post build actions
To configure -> Post-build operation -> Add post build steps -> Deploy war/ear to a container WAR/EAR files Input target/*.war Containers -> Add Container -> Tomcat 9.x Remote -> Credentials, Click Add -> Jenkins User name input tomcat, Password input tomcat, Description input tomcat-auth-password, Click Add Credentials" Next Pull selection tomcat-auth-password Tomcat URL Input http://192.168.37.108:8080 Click save Click on Build Now, Try to build the project 3) After successful deployment , Refresh http://192.168.37.108:8080/manager/html page , You can find one more item in the application , Click on the new item to access

Maven project structure
1) Modify source code And submit to gitlab
cd /root/web_demo
vim src/main/webapp/index.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title> Demo project home page </title>
</head>
<body>
If you see this page , On behalf of the successful deployment of the project !
<hr/> ## Add line feed
<a href="/addUser"> Add users </a> ## add to
</body>
</html>
git add .
git commit -m " Add users "
git push -u origin master ## account number / password :zhangsan/[email protected]2) install maven integration plug-in unit
Manage Jenkins -> Management plug-in - Optional plug-ins -> Search for Maven Integration The plug-in can be installed directly
3) establish maven project
newly build item ->. The name of the task (web_ demo_ maven) Build a individual maven project -> determine Source code management : choice Git, Repository URL: [email protected]:devops_group/web_demo.git CredentialsI Drop down to select gitlab-auth-ssh, Click save
Build: Root POM Input pom. xml # Appoint pom. xml Path to file
Goals and options
Input clean package # Input maven Instructions , Do not write mvn
Post-build operation : Add post build steps -> Deploy war/ear to a container
WAR/EAR files Input target/*.war
Containers -> Add Container -> Tomcat 9.x Remote -> Credentials" Next Pull selection tomcat-auth-passwordTomcat URL Input http:/ /192.168.37.108:8080 Click save Click on Build Now, Try to build the project Browser access project : http://192.168.37.108:8080/web_demo-1.0-SNAPSHOT/

summary
The developer submits the code to the code hosting server gitlab On , stay CI Tools jenkins Configure the server , Source management uses Git Pull the code . Add... To the credentials Gitlab Users and passwords in the project ( Or use ssh Key pairs are used as relevant credentials ) Add related to source code management http Address ( or ssh Address ), Select the corresponding credentials . stay gitlab To pull the code . Directly specify at build time pom.xml Boot configuration file for , Keep up with the relevant maven Instructions clean package Compile the corresponding code , pack . And then use the tools Deploy war/ear to a container Package and compile war Package is deployed to the tomcat Server . The whole process is in jenkins Automated operations performed on continuously integrated processes .
边栏推荐
- Expression tree - medium order printout
- Et5.0 simply transform referencecollectorieditor
- [backtrader source code analysis 7] analysis of the functions for calculating mean value, variance and standard deviation in mathsupport in backtrader (with low gold content)
- Influence of higher order poles on waveform
- Illustrator tutorial, how to add dashes and arrows in illustrator?
- [Latex] 插入图片
- Kotlin 协程的作用域构建器 coroutineScope与runBlocking 与supervisorScope,协程同步运行,协程挂掉的时候其他协程如何不被挂掉。
- 深度学习训练多少轮?迭代多少次?
- 论文笔记:STMARL: A Spatio-Temporal Multi-AgentReinforcement Learning Approach for Cooperative Traffic
- 今日睡眠质量记录74分
猜你喜欢

人神共愤,唐山“群殴女性事件”细节...

Kotlin 协程的四种启动模式

Pipeline pipeline project construction

MySQL index

Minimum spanning tree problem

Kotlin collaboration, the life cycle of a job

三栏简约typecho主题Lanstar/蓝星typecho主题

Aunt learning code sequel: ability to sling a large number of programmers

论文笔记:STMARL: A Spatio-Temporal Multi-AgentReinforcement Learning Approach for Cooperative Traffic

Expression tree - medium order printout
随机推荐
Key point detection data preparation and model design based on u-net Network -- detection model of four key points of industrial components
pytorch是什么?解释pytorch的基本概念
[003] embedded learning: creating project templates - using stm32cubemx
Aunt learning code sequel: ability to sling a large number of programmers
【北亚服务器数据恢复】虚拟机文件丢失导致Hyper-V服务瘫痪的数据恢复案例
408 true question - division sequence
[imx6ull] video monitoring project (USB camera +ffmepeg)
With a market value of more than trillion yuan and a sales volume of more than 100000 yuan for three consecutive months, will BYD become the strongest domestic brand?
Addition and modification of JPA
Pipeline流水线项目构建
Influence of higher order poles on waveform
. The way to prove the effect of throwing exceptions on performance in. Net core
Three threads print digital demo alternately
Cards are unpredictable
Hard (magnetic) disk (II)
Mongodb array operation
Et5.0 value type generation
Aof persistence
OceanBase 雄踞墨天轮2021年度中国数据库魔力象限领导者
Hard (magnetic) disk (I)