jenkins配置流水线

新建任务,随便选一个名字,选中流水线

配置git的用户名和密码,记录ID,后面配置流水线的时候用。

bash 复制代码
pipeline {
    agent any

    stages {
        
        stage('stop app'){
            steps {
                script {
                  def remote = [:]
                  //配置服务地址,用户名和密码
                  remote.name = 'prd'
                  remote.host = '114.116.1.1'
                  remote.user = 'test'
                  remote.password = 'test@123'
                  remote.allowAnyHosts = true
                  //连到服务器,停止服务器
                  sshCommand remote: remote, command: "cd /data/test/gateway;sudo sh stop.sh"
                  sshCommand remote: remote, command: "cd /data/test/infra;sudo sh stop.sh"
                  sshCommand remote: remote, command: "cd /data/test/system;sudo sh stop.sh"
                  sshCommand remote: remote, command: "cd /data/test/test;sudo sh stop.sh"
                  sshCommand remote: remote, command: "cd /data/test/member;sudo sh stop.sh"
                  
                }
            }
        }
        
        stage('pull code') {
            steps {
            //连到GIT地址,用上面配置的凭据ID
                checkout scmGit(branches: [[name: '*/master']], extensions: [], userRemoteConfigs: [[credentialsId: '0a60a90e-6898-446c-bf49-d452dc1445a0', url: 'https://e.coding.net/g-cine6025/testshujuxiangmu/test.git']])
            }
        }
        stage('build project') {
            steps {
                sh 'mvn -DskipTests clean package'
            }
        }
        stage('start gateway'){
            steps {
                script {
                  def remote = [:]
                  remote.name = 'prd'
                  remote.host = '114.116.1.1'
                  remote.user = 'test'
                  remote.password = 'test@123'
                  remote.allowAnyHosts = true
                  sshCommand remote: remote, command: "ls -lrt"
                  //先从docker中的jar拷到本机,查看你的配置的生成的jar包在哪个路径
                  sshCommand remote: remote, command: "sudo cp /var/jenkins_home/workspace/部署管理后应用/gateway/target/gateway.jar /data/test/gateway/gateway.jar"
                  sshCommand remote: remote, command: "sudo cp /var/jenkins_home/workspace/部署管理后应用/module-infra/module-infra-biz/target/module-infra-biz.jar /data/test/infra/module-infra-biz.jar"
                  sshCommand remote: remote, command: "sudo cp /var/jenkins_home/workspace/部署管理后应用/module-system/module-system-biz/target/module-system-biz.jar /data/test/system/module-system-biz.jar"
                  sshCommand remote: remote, command: "sudo cp /var/jenkins_home/workspace/部署管理后应用/module-test/module-biz/target/module-biz.jar /data/test/test/module-biz.jar"
                  sshCommand remote: remote, command: "sudo cp /var/jenkins_home/workspace/部署管理后应用/module-member/module-member-biz/target/module-member-biz.jar /data/test/member/module-member-biz.jar"
                  //执行启动命令
                  sshCommand remote: remote, command: "cd /data/test/gateway;sudo sh start.sh"
                  sshCommand remote: remote, command: "cd /data/test/infra;sudo sh start.sh"
                  sshCommand remote: remote, command: "cd /data/test/system;sudo sh start.sh"
                  sshCommand remote: remote, command: "cd /data/test/test;sudo sh start.sh"
                  sshCommand remote: remote, command: "cd /data/test/member;sudo sh start.sh"
                  
                }
            }
        }
    }
}
相关推荐
程序员没睡醒44 分钟前
《Kali Linux从安装到武器化配置:打造你的数字军火库》
linux·运维·服务器·渗透测试·kalilinux·匿名攻防
m0_603888712 小时前
如何将本地连接服务器中的文件内容复制到本机的剪贴板
运维·服务器
_extraordinary_9 小时前
Linux基本指令(三)+ 权限
linux·运维·服务器
青春:一叶知秋10 小时前
Reactor模型说明
运维·服务器
和舒貌11 小时前
Linux系统编程基础详解
linux·运维·服务器·基础
蛊明14 小时前
下载CentOS 10
linux·运维·centos
北京-宏哥14 小时前
Linux系统安装MySQL5.7(其他版本类似)避坑指南
linux·运维·服务器
qw94914 小时前
Linux 高级篇 日志管理、定制自己的Linux系统、备份与恢复
linux·运维·服务器
丶只有影子14 小时前
【Nacos】从零开始启动Nacos服务(windows/linux)
linux·运维·windows·微服务·springcloud
青年vs阳光14 小时前
win10把c盘docker虚拟硬盘映射迁移到别的磁盘
运维·docker·容器