当前位置:网站首页>Jenkins Automated Deployment
Jenkins Automated Deployment
2022-07-21 02:44:00 【llp1110】
Jenkins Automated Deployment
1. Basic environment construction
Reference resources :https://llinp.cn/articles/2022/01/01/1640998831081.html
1.1 Virtual machine environment construction
1.2 install jdk Running environment
# Enter into src Under the table of contents
cd /usr/local/src/
# establish java File directory
mkdir java
# Will download okay jdk The compressed package is stored in java Directory , And use the decompression command to decompress
tar -zxvf jdk-8u212-linux-x64.tar.gz
# Modify environment variables
vim /etc/profile
#set java env
JAVA_HOME=/usr/local/src/java/jdk1.8.0_212
JAVA_BIN=/usr/local/src/java/jdk1.8.0_212/bin
PATH=$JAVA_HOME/bin:$PATH
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME JAVA_BIN PATH CLASSPATH
# Through the command source /etc/profile Give Way profile The document takes effect immediately
source /etc/profile
# Test for successful installation
java -version
The effect of the following figure shows jdk The environment has been configured
1.3 install maven
# First step : Upload or download the installation package
cd/usr/local
apache-maven-3.6.1-bin.tar.gz
# The second step : Unzip the installation package
tar -zxvf apache-maven-3.6.1-bin.tar.gz
# The third step : Establish a soft connection
ln -s /usr/local/apache-maven-3.6.1/ /usr/local/maven
# Step four : Modify environment variables
vim /etc/profile
export MAVEN_HOME=/usr/local/maven
export PATH=$PATH:$MAVEN_HOME/bin
# Through the command source /etc/profile Give Way profile The document takes effect immediately
source /etc/profile
# Step five 、 Test for successful installation
mvn –v
1.4 install git
yum -y install git
1.5 install docker
# verification docker Is it installed well , Command view docker Version of , In the virtual machine docker It's set up ,1.7.3 To 1.7.1 Do not execute the installation command in .
docker version
# Uninstall the old version of docker And its related dependencies
sudo yum remove docker docker-common container-selinux docker-selinux docker-engine
# install yum-utils**, It provides ** yum-config-manager**, Can be used to manage yum Source **
sudo yum install -y yum-utils
# add to yum Source
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
# Update index
sudo yum makecache fast
# install docker-ce
sudo yum install docker-ce
# see docker state
systemctl status docker
# start-up docker
systemctl start docker
# start-up
service docker start
# stop it
service docker stop
# restart
service docker restart
# Verify that the installation was successful
docker info
# Check the installed image
docker images
# Look at the container
# Show all containers
docker ps -a
# Show all running containers
docker ps
For detailed installation tutorials, see :
https://llinp.cn/articles/2022/01/09/1641738726437.html#toc_h2_0
2. install jekins
download jenkins
Official address :https://www.jenkins.io/download/
install
# First step : Upload or download the installation package
cd/usr/local/jenkins
jenkins.war
# The second step : start-up
#nohup- Background silent start
#/usr/local/jenkins/jenkins.war war Package path
#/usr/local/jenkins/jenkins.out Log input path
#nohup & Background silent start
nohup java -jar /usr/local/jenkins/jenkins.war >/usr/local/jenkins/jenkins.out &
# The third step : visit
http://ip:8080
Effect after successful installation , At the beginning of the visit, there will be an initialization interface without waiting for operation , If you wait a long time and don't change kill -9 Process number , Restart it
Initialization interface
Password unlock
cat /root/.jenkins/secrets/initialAdminPassword
Be careful
The default is foreign image , Download is very slow . It is recommended to close the browser and configure the domestic image
3. Configure domestic image
The official download of plug-ins is slow Update download address
cd { Yours Jenkins working directory }/updates # Enter the update configuration location
# Replace the image address with Zeng
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
This is the directly modified configuration file , If the front Jenkins use sudo Start up , So here are two sed You need to add sudo(linux If the login account is not a super administrator )
3.1 stop it jenkins
# see jenkins process
ps -ef|grep jenkins
# Kill the process , stop it jenkins
kill -9 37820
Enter into cd /root/.jenkins Directory
cd /root/.jenkins
Get into updates Catalog
cd updates/
Execute the statement to replace the image address with the domestic image address
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
Look at the replaced default.json Content (cat、tail You can view the contents of the file )
tail default.json
or
cat default.json
restart jenkins
nohup java -jar /usr/local/jenkins/jenkins.war >/usr/local/jenkins/jenkins.out &
4. Installing a plug-in
Choose to install the recommended plug-ins
Installing
Installation successful
Fill in normally
Configure access address
The default port here is 8080 Switch as needed
Go to this screen jenkins Installation of is complete
5.jenkins To configure
jenkins Configuration preparation for
1. download jdk
2. download maven
3. download git
4. download jenkins.war https://jenkins.io/index.html
Download address :
link :https://pan.baidu.com/s/1E-uQbZLVRGWkR_14xuPCLg
Extraction code :35sv
Sign in
jenkins Management interface
Enter global configuration
5.1 To configure jdk
# see jdk The installation path
which jdk
Here mine jdk The installation path is /usr/local/src/java/jdk1.8.0_212
5.2 To configure maven
5.3 To configure git
# see git The installation path
which git
6.jenkins Automated Deployment
6.1 Modification item
modify pom file
Modify the packing method
<packaging>jar</packaging>
Packaging plug-in
<build>
<finalName>demojenkins</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
6.2 stay jenkins Management interface creates automated tasks
establish item
Source management fill in the project git Address
Add user name and password
Constructing environment
Script files
#!/bin/bash
#maven pack
mvn clean package
echo 'package ok!'
echo 'build start!'
cd ./
service_name="demojenkins"
service_prot=8761
# Look at the mirror image id Judge demojenkins Is there a mirror image
IID=$(docker images | grep "$service_name" | awk '{print $3}')
echo "IID $IID"
if [ -n "$IID" ]
then
# Delete the image if it exists
echo "exist $SERVER_NAME image,IID=$IID"
# delete mirror
docker rmi -f $service_name
echo "delete $SERVER_NAME image"
# Delete and rebuild
docker build -t $service_name .
echo "build $SERVER_NAME image"
else
# If it doesn't exist, build it directly
echo "no exist $SERVER_NAME image,build docker"
# structure
docker build -t $service_name .
echo "build $SERVER_NAME image"
fi
# Look at the container id, See which containers are running
CID=$(docker ps | grep "$SERVER_NAME" | awk '{print $1}')
echo "CID $CID"
if [ -n "$CID" ]
then
# Stop deleting if the same container exists
echo "exist $SERVER_NAME container,CID=$CID"
# stop it
docker stop $service_name
# Delete container
docker rm $service_name
else
echo "no exist $SERVER_NAME container"
fi
# start-up , Create a container
docker run -d --name $service_name --net=host -p $service_prot:$service_prot $service_name
# View startup log , Select whether to view
#docker logs -f $service_name
You need to start before building docker
Start the mission
View console output
So far, the project has been built
Final effect
6.3 Add
Build the structure
What I use here jenkins yes 2.319.2 The version image of has been changed , The representation of the icon can be seen from the explanation of
The first column is “ The last build status displays ”, It's a circular icon , There are generally four kinds of :
Blue : Building a successful ;
yellow : Not sure , It is possible to build successfully , But it contains errors ;
Red : Build failed ;
gray : The project has never been built , Or it's disabled ;
Blue as shown above , Indicates that the build was successful .
Be careful : The time of manually triggering the build and the time of automatically timing the build do not affect each other .
边栏推荐
- Returns the quarter and year of the date provided
- How does excel choose specific numbers to sum? Excel method of selecting specific numbers for summation
- 记录uni-app 打包成apk后获取定位
- 检查日期是否有效
- Introduction, installation and basic use of mongodb database
- A detailed explanation of the implementation principle of go Distributed Link Tracking
- 使用 NSProxy 实现消息转发
- Check whether the date is valid
- 有奖调研 | 让虚拟照入现实的完美AR开发平台长什么样?
- gerrit系统如何配置访问控制
猜你喜欢
Implementation principle of scala function & method and function & method
Wps如何清除最近打开的记录?Wps清除本地记录的方法
怎么批量删除Excel电子表格中不同的文字?
Kingdee's "answer sheet" forecast in the first half of the year: key customer strategy continued to break through, and arr increased by more than 45% year-on-year
RGB dot matrix display based on esp32
在线问题反馈模块实战(八):实现图片上传功能(上)
从0到1建设智能灰度数据体系:以vivo游戏中心为例
How does excel choose specific numbers to sum? Excel method of selecting specific numbers for summation
cnvd_ 2019_ twenty-two thousand two hundred and thirty-eight
swift 使用SMAMB2包,重新打包的心酸历程
随机推荐
百度交易中台之钱包系统架构浅析
全栈代码测试覆盖率及用例发现系统的建设和实践
Big guys ask a question, flinksql writes mysql, non empty fields can't be written in, and I don't give the default value. What's the matter, big guys
A detailed explanation of the implementation principle of go Distributed Link Tracking
The beta version of typera is expired and cannot be used normally
Virtual reality coexists, building a digital intelligence life | HMS core Sparkle application innovation sub forum registration launch
How to add columns in PPT histogram
【MUDUO 】Channel通道
【SELECT、POLL的缺点,以及EPOLL的优势】
Real time debugging practice based on attach to process
虚拟主机代理商需要注意什么?
得物基于Attach to Process的实时调试实践
Returns the quarter and year of the date provided
Detailed explanation of getchar () function in C language
【MUDUO 日志系统1】Logger输出
apple 为什么要改 objc
TCP协议的相关特性
Introduction, installation and basic use of mongodb database
Software interface and simple system simulation
Binary tree OJ exercise