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"
                  
                }
            }
        }
    }
}
相关推荐
zhangfeng113316 分钟前
宝塔服务器完全可以安装 Git,进行版本管理,而且非常简单
运维·服务器·人工智能·git·编程
逸Y 仙X1 小时前
文章二十五:ElasticSearch 分页查询
java·大数据·数据库·elasticsearch·搜索引擎·全文检索
科研前沿1 小时前
SpaceOS™空间计算底座与五大自研引擎,实现多项关键技术突破
大数据·运维·人工智能·算法·重构
阿里云大数据AI技术2 小时前
重构搜索范式:阿里云 Elasticsearch 开启“Agent 原生”时代,打造企业级 AI 记忆湖
人工智能·elasticsearch·阿里云·agent·搜索
德迅云安全-小潘3 小时前
APP运营服务器配置全攻略:从选型到网络安全,你需要知道的一切
运维·服务器·web安全
Yupureki3 小时前
《Linux网络编程》9.数据链路层原理
linux·运维·服务器·网络
切糕师学AI3 小时前
Remmina:Linux 平台的全能远程桌面客户端详解
linux·运维·远程控制·远程桌面·remmina
dualven_in_csdn3 小时前
【assist】 需要用到的方法
linux·运维·服务器
diangedan4 小时前
focuswindow
linux·运维·服务器
私人珍藏库4 小时前
[吾爱大神原创工具] 网卡切换小工具
运维·服务器