jenkins pipeline 配置案例
pipeline {
agent any
stages {
stage('Stop Service') {
steps {
sh "docker stop server-B"
sh "docker stop service-big-data"
sh "ssh root@server-node-n docker stop service-A-center"
sh "ssh root@server-node-n docker stop service-B-center"
sh "ssh root@server-node-n docker stop service-C-center"
sh "ssh root@server-node-n docker stop server-A-websiter"
sh "ssh root@server-node-n docker stop server-B-websiter"
}
}
stage('Git Code') {
steps {
git branch: 'main', credentialsId: 'e509e172-56ef-4fcf-af87-2cc883671c56', url: 'git@your-git-info:java/your-project.git'
}
}
stage('Maven Build') {
steps {
sh "mvn clean && mvn package -Dmaven.test.skip=true "
}
}
stage('Start Service') {
steps {
sh "cp -f server-B/target/server-B.jar /opt/docker/cloud-parent/server-B/"
sh "docker start server-B"
sh "cp -f service-big-data/target/service-big-data.jar /opt/docker/cloud-parent/service-big-data/"
sh "docker start service-big-data"
sh "scp -r service-A-center/target/service-A-center.jar root@server-node-n:/opt/docker/cloud-parent/service-A-center"
sh "ssh root@server-node-n docker start service-A-center"
sh "scp -r service-B-center/target/service-B-center.jar root@server-node-n:/opt/docker/cloud-parent/service-B-center"
sh "ssh root@server-node-n docker start service-B-center"
sh "scp -r service-C-center/target/service-C-center.jar root@server-node-n:/opt/docker/cloud-parent/service-C-center"
sh "ssh root@server-node-n docker start service-C-center"
sh "scp -r server-A-website/target/server-A-website.jar root@server-node-n:/opt/docker/cloud-parent/server-A-website"
sh "ssh root@server-node-n docker start server-A-website"
sh "scp -r server-B-website/target/server-B-website.jar root@server-node-n:/opt/docker/cloud-parent/server-B-website"
sh "ssh root@server-node-n docker start server-B-website"
}
}
}
}
提示:
@server-node-n 为另外的目标服务器,且与Jenkins部署服务器进行了免密登录设置
Jenkins 部署参考:
Jenkins 2.319.1 LTS WAR文件安装方式-左搜 (leftso.com)
Linux免密登录参考:
Linux 配置免密证书登录-左搜 (leftso.com)
https://www.leftso.com/article/938.html