Jenkins-docker流水线发布环境

1.Jenkins需要安装 Maven Integration SSH Pipeline Steps 两个插件

2.各个服务器需要安装docker 并配置可以访问harbor私服

vi /etc/docker/daemon.json



{ "registry-mirrors": ["https://wb2g6zxl.mirror.aliyuncs.com"],
"insecure-registries":["ip:端口"]
}

sudo service docker restart

3.需要在各种服务安装 docker-compose

# 下载
wget https://github.com/docker/compose/releases/download/1.24.1/docker-compose-Linux-x86_64
# 移动到/user/local/bin
mv docker-compose-Linux-x86_64 /user/local/bin
# 改名
mv docker-compose-Linux-x86_64 docker-compose
#给docker-compose增加权限
sudo chmod +x /usr/local/bin/docker-compose

4.在/home文件下创建 docker-compose.yml配置文件

version: '2'
services:
  billing-server:
    container_name: billingserver
    image: billing-server:latest
    restart: always
    network_mode: "host"
    environment:
    - cenv=uat
    volumes:
      - /home/test/upload:/docker/upload
      - /home/test/license:/docker/license
      - /home/test/logs/billing-server:/docker/logs
      - /home/test/dump/billing-server:/docker/dump

5.在Jenkins创建一个流水线项目

 

 137.66.33.4为docker私服 ip

pipeline {
    agent any
    stages {
            stage("选择版本") {
            steps {
                timeout(time: 1, unit: 'MINUTES') {
                script {
                    env.VERSION_ENV = input message: 'select-version', ok: 'deploy',
                        parameters: [string(name: 'version', trim: false)]

                        }
                    }
                }
            }
            
            stage("deploy-server-01 ") {
            steps {
                timeout(time: 30, unit: 'MINUTES') {
                script {
                        def remote = [:]
                        remote.name='ip' #服务器ip
  	                    remote.host = 'ip'
  	                    remote.user = 'xxx'
                        remote.password ='xxx'
  	                    remote.allowAnyHosts = true
                        sshCommand remote: remote, command:"docker rm -f billingserver; docker rmi -f billing-server:latest ; sleep 3s; docker login -u xx -pXX 137.66.33.4:8088; docker pull 137.66.33.4:8088/mxbc/billing-server:${env.VERSION_ENV}; docker tag 137.66.33.4:8088/mxbc/billing-server:${env.VERSION_ENV} billing-server:latest; docker rmi 137.66.33.4:8088/mxbc/billing-server:${env.VERSION_ENV};cd /home/test/yml/billing-server;docker-compose -f docker-compose.yml up -d"

                       
                        }
                    }
                }
            }
            
            
            stage("deploy-web-01 ") {
            steps {
                timeout(time: 30, unit: 'MINUTES') {
                script {
                        def remote = [:]
                        remote.name='ip'
  	                    remote.host = 'ip'#服务器ip
  	                    remote.user = 'xx'
                        remote.password ='xx'
  	                    remote.allowAnyHosts = true
                        sshCommand remote: remote, command:"docker rm -f billingweb; docker rmi -f billing-web:latest ; sleep 3s; docker login -u xx -pXX 137.66.33.4:8088; docker pull 137.66.33.4:8088/mxbc/billing-web:${env.VERSION_ENV}; docker tag 137.66.33.4:8088/mxbc/billing-web:${env.VERSION_ENV} billing-web:latest; docker rmi 137.66.33.4:8088/mxbc/billing-web:${env.VERSION_ENV};cd /home/test/yml/billing-web;docker-compose -f docker-compose.yml up -d"

                         }
                    }
                }
            }
            
            
            
             
            
           
             
            
            
            
        }
    }

6.立即构建 输入私服 镜像文件的tags

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值