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
|