构建项目位置
/var/lib/jenkins/workspace/jenkins_project_name
手动构建:
1 新建自由风格jenkins项目---构建---执行shell
rm -rf project1/
git clone [email protected]: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/ [email protected]:/data/tomcat/webapps/web01/
scp -r project1/
[email protected]:/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 回滚上面的项目到上一个版本
pwd
#rm -rf project1/
#git clone [email protected]:group1/project1.git
cd project1
git reset --hard HEAD^
#说明,一个^是回到上一个版本,两个^是回到上上个版本
#ssh 192.168.1.17 "/etc/init.d/tomcat stop"
#ssh 192.168.1.18 "/etc/init.d/tomcat stop"
scp -r ./ [email protected]:/data/tomcat/webapps/web01/
scp -r ./
[email protected]:/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 新建流水线项目---Pipeline---脚本
node {
stage('git code') {
echo 'git code'
sh 'rm -rf project1/'
sh 'git clone [email protected]: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/ [email protected]:/data/tomcat/webapps/web01/'
sh 'scp -r project1/
[email protected]:/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"'
}
}

配置自动触发构建
1 在jenkins上:
配置全局安全---勾选Allow anonymous read access---取消Prevent Cross Site Request Forgery exploits
点击某个jenkins项目test1--配置---Build Triggers---勾选Trigger builds remotely---输入Authentication Token:123123---勾选:Build when a change is pushed to GitLab
2 在gitlab上:
点击扳手图标--Settings--Network--Outbound requests--勾选Allow requests to the local network from hooks and services
点击gitlab项目project1---Settings---Intergrations---在RUL中输入:http://192.168.1.15:8080/buildByToken/build?job=test1&token=123123
---勾选Trigger下的Push events---勾选Enable SSL verification---最后点击Add Webhook---然后test测试
说明:192.168.1.15是jenkins的地址,test1是jenkins中的项目名