CI/CD operation manual in traditional cloud environment (6) jenkins manual build example and implementation of automatic trigger build
Build Project Location
/var/lib/jenkins/workspace/jenkins_project_name
Manual build:
1 New free-style jenkins project---build--execute shell
rm -rf project1/
git clone git@192.168.1.14:group1/project1.git
ssh 192.168.1.17 "/etc/init.d/tomcat stop"
ssh 192.168.1.18 "/etc/init.d/tomcat stop"
scp -r project1/ root@192.168.1.17:/data/tomcat/webapps/web01/
scp -r project1/ root@192.168.1.18:/data/tomcat/webapps/web01/
ssh 192.168.1.17 "/etc/init.d/tomcat start"
ssh 192.168.1.18 "/etc/init.d/tomcat start"
2 Roll back the above item to the previous version
pwd
#rm -rf project1/
#git clone git@192.168.1.14:group1/project1.git
cd project1
git reset --hard HEAD^
#Description, one ^is back to the previous version, two ^is back to the previous version
#ssh 192.168.1.17 "/etc/init.d/tomcat stop"
#ssh 192.168.1.18 "/etc/init.d/tomcat stop"
scp -r ./ root@192.168.1.17:/data/tomcat/webapps/web01/
scp -r ./ root@192.168.1.18:/data/tomcat/webapps/web01/
#ssh 192.168.1.17 "/etc/init.d/tomcat start"
#ssh 192.168.1.18 "/etc/init.d/tomcat start"
3 New Pipeline Project---Pipeline--Script
node {
stage('git code') {
echo 'git code'
sh 'rm -rf project1/'
sh 'git clone git@192.168.1.14:group1/project1.git'
}
stage('stop tomcat') {
echo 'stop tomcat'
sh 'ssh 192.168.1.17 "/etc/init.d/tomcat stop"'
sh 'ssh 192.168.1.18 "/etc/init.d/tomcat stop"'
}
stage('scp code') {
echo 'scp code'
sh 'scp -r project1/ root@192.168.1.17:/data/tomcat/webapps/web01/'
sh 'scp -r project1/ root@192.168.1.18:/data/tomcat/webapps/web01/'
}
stage('stop tomcat') {
echo 'stop tomcat'
sh 'ssh 192.168.1.17 "/etc/init.d/tomcat start"'
sh 'ssh 192.168.1.18 "/etc/init.d/tomcat start"'
}
}
Configure auto-trigger builds
1 on Jenkins:
Configure global security---Check Allow anonymous read access--Cancel Prevent Cross Site Request Forgery explosions
Click on a jenkins project test1--Configure---Build Triggers---Check Trigger builds remotely--Enter Authentication Token: 123123--Check: Build when a change is pushed to GitLab
2 on gitlab:
Click on the wrench icon--Settings--Network--Inbound requests--Check Allow requests to the local network from hooks and services
Click gitlab project1---Settings---Intergrations---Enter in RUL: 192.168.1.15:8080/buildByToken/build? job=test1&token=123123
---Check Push events under Trigger---Check Enable SSL verification---Finally click Add Webhook---Then test
Note: 192.168.1.15 is the address of jenkins, test1 is the project name in jenkins