jenkins  pipeline​​​​​​​ 配置案例

位置:首页>文章>详情   分类: 教程分享 > Java教程   阅读(609)   2023-03-28 11:29:14
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)

标签: Jenkins
地址:https://www.leftso.com/article/938.html

相关阅读

WAR文件 安装Jenkins 的 Web 应用程序存档 (WAR) 文件版本可以安装在任何运行 Jenkins 支持的 Java 版本的操作系统或平台上
问题描述直接安装的Jenkins,然后每次构建代码发现时间都和当前的时间不对,列表差8小时问题解决首先找到Jenkins的命令运行界面 由于我是设置的中午界面,所以目标为系统管理-&gtl;脚本...
jenkins是devops神器,本篇文章介绍如何安装和使用jenkins部署Spring Boot项目jenkins搭建 部署分为三个步骤;第一步,jenkins安装第二步,插件安装和配置第三...
jenkins  pipeline 配置案例pipeline { agent any stages { stage('Stop Service') { ...