Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

CI/CD operation manual in traditional cloud environment (6) jenkins manual build example and implementation of automatic trigger build

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report