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"
                  
                }
            }
        }
    }
}
相关推荐
欧先生^_^43 分钟前
docker的文件系统Overlay2
运维·docker·容器
一只小白跳起来1 小时前
重新安装VMware tools为灰色无法点击问题解决|读取电脑文件的共享文件夹方法
运维·ubuntu·vmware
长河1 小时前
Kafka系列教程 - Kafka 运维 -8
运维·分布式·kafka
刘若水2 小时前
Linux: 进程信号初识
linux·运维·服务器
阳小江3 小时前
Docker知识点
运维·docker·容器
qr9j422333 小时前
elasticsearch 如果按照日期进行筛选
大数据·elasticsearch·jenkins
DavidSoCool4 小时前
es分页边界数据重复问题处理
大数据·elasticsearch·搜索引擎
心灵宝贝4 小时前
Tomcat 部署 Jenkins.war 详细教程(含常见问题解决)
java·tomcat·jenkins
只是橘色仍温柔4 小时前
xshell可以ssh连接,但vscode不行
运维·vscode·ssh
IT里的交易员4 小时前
【系统】换硬盘不换系统,使用WIN PE Ghost镜像给电脑无损扩容换硬盘
运维·电脑