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"
                  
                }
            }
        }
    }
}
相关推荐
秋风起,再归来~3 分钟前
【Linux庖丁解牛】—进程优先级!
linux·运维·服务器
Lalolander29 分钟前
设备制造行业如何避免项目管理混乱?
运维·制造·工程项目管理·四算一控·epc·环保设备工程·设备制造
LucianaiB1 小时前
【金仓数据库征文】_AI 赋能数据库运维:金仓KES的智能化未来
运维·数据库·人工智能·金仓数据库 2025 征文·数据库平替用金仓
prinrf('千寻)1 小时前
nacos设置权重进行负载均衡不生效
运维·负载均衡
Lary_Rock1 小时前
Android 编译问题 prebuilts/clang/host/linux-x86
android·linux·运维
绵绵细雨中的乡音1 小时前
Linux进程学习【基本认知】
linux·运维·学习
珹洺3 小时前
Linux操作系统从入门到实战(三)Linux基础指令(上)
linux·运维·服务器
剁椒排骨3 小时前
win11什么都不动之后一段时间黑屏桌面无法显示,但鼠标仍可移动,得要熄屏之后才能进入的四种解决方法
运维·windows·经验分享·计算机外设·win11·win10
angushine3 小时前
让Docker端口映射受Firewall管理而非iptables
运维·docker·容器
归寻太乙3 小时前
Linux环境变量
linux·运维·服务器