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"
                  
                }
            }
        }
    }
}
相关推荐
自律的kkk5 分钟前
docker配置镜像加速器
运维·docker·容器
檀越剑指大厂6 分钟前
【Elasticsearch系列四】ELK Stack
大数据·elk·elasticsearch
繁依Fanyi33 分钟前
828 华为云征文|华为 Flexus 云服务器部署 RustDesk Server,打造自己的远程桌面服务器
运维·服务器·开发语言·人工智能·pytorch·华为·华为云
优思学院40 分钟前
优思学院|如何从零开始自己学习六西格玛?
大数据·运维·服务器·学习·六西格玛黑带·cssbb
Flying_Fish_roe1 小时前
linux-软件包管理-包管理工具(RedHat/CentOS 系)
linux·运维·centos
千寻简1 小时前
Cursor免费 GPT-4 IDE 工具的保姆级使用教程
java·运维·ide·ai
2401_840192271 小时前
ELFK日志分析平台,架构和通信
elk·elasticsearch·架构
Jerry 二河小鱼2 小时前
在Linux中安装FFmpeg
linux·运维·服务器·ffmpeg
比花花解语2 小时前
怎么使用nginx把80端口代理到想要的端口?
运维·nginx
APItesterCris2 小时前
API 接入前的安全防线:注意事项全梳理
大数据·运维·服务器·开发语言·数据仓库·安全