加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Deploy.groovy 4.40 KB
一键复制 编辑 原始数据 按行查看 历史
lenz_jenkins 提交于 2022-07-05 03:37 . qianyi
/** ========================= 标准配置 ============================= **/
import com.trax.devops.publish.*
import hudson.model.*
@Library('trax-cicd-lib') _
//发布的镜像
def imageMap = [:]
def group = 'dockerimg.lenztechretail.com'
def nameSpace = 'tope'
//maven版本,用来构建的脚本,确定 snapshot / release
def mavenVersion = "release"
//版本号
//String tag = "${BRANCH_NAME}.${MAIN_VERSION}.${SMALL_VERSION}.${BUILD_NUMBER}"
String tag = "${BUILD_TAG}"
//环境列表
def deployEnvList = ['prod']
/** ========================= 应用自定义 ============================= **/
//应用前缀
//应用前缀
def appPrefix = "xxl"
//项目名
def projectName = "${appPrefix}-job"
//服务所在目录,会根据该目录结合appName寻找jar包进行docker镜像构建
def serviceDir = "."
//发布的应用
def appNames = ["job-manager"]
//git仓库地址
def gitUrl = "git@gitee.com:ppz_bj/${projectName}.git"
//通知版本号的dataID
def nacosDataId = "${projectName}.yml"
/** ========================= 发布环境(仅包含发布时使用) ============================= **/
//发版目录
def projectDir = "/data/projects/${nameSpace}/${projectName}"
//默认的发布机器
def targetHosts = [
['publicIp': '172.16.0.69', 'internalIp': '172.16.0.69','id':'']
]
//DEV发布机器
def devHosts = [
['publicIp': '39.106.254.155', 'internalIp': '172.17.0.18','id':'']
]
//DEV发布机器
def testHosts = [
['publicIp': '82.157.12.159', 'internalIp': '10.0.20.36','id':'']
]
//发布机器Uat
def uatHosts = [
[:]
]
// 正式服务器ip列表(阿里云)
def alphaHosts = [
['publicIp': '39.105.151.106', 'internalIp': '172.17.138.94' , 'id':''],
['publicIp': '101.200.60.152', 'internalIp': '172.17.94.232' , 'id':''],
['publicIp': '47.94.90.69', 'internalIp': '172.17.94.216' , 'id':'']
]
def gammaHosts = [
[:]
]
// 正式服务器ip列表(腾讯)
def deltaHosts = [
[:]
]
//动作
def action = "deploy"
//发布用户
def user = 'ppz'
pipeline {
agent any
stages {
stage('Git Checkout') {
steps {
script {
echo "Checkout...${BRANCH_NAME}"
checkout scm
}
}
}
stage('Branch Check') {
steps {
script {
checkTag(BRANCH_NAME)
}
}
}
stage('Input Env') {
steps {
timeout(time: 1, unit: 'MINUTES') {
script {
env.DEPLOY_ENV = input message: '选择部署的环境', ok: 'deploy',
parameters: [choice(name: 'DEPLOY_ENV', choices: ['dev','test','uat','alpha', 'gamma' , 'delta' ], description: '选择部署环境')]
println("deploy to ${env.DEPLOY_ENV}")
deployEnvList = ["${env.DEPLOY_ENV}"]
switch ("${env.DEPLOY_ENV}") {
case 'dev':
targetHosts = devHosts
break;
case 'test':
targetHosts = testHosts
break;
case 'uat':
targetHosts = uatHosts
break;
case 'alpha':
targetHosts = alphaHosts
break;
case 'gamma':
targetHosts = gammaHosts
break;
case 'delta':
targetHosts = deltaHosts
break;
default:
println('error env')
}
println('本次发布地址:' + targetHosts)
}
}
}
}
stage('Deploy') {
steps {
script {
echo '发布......'
if (currentBuild.result == null || currentBuild.result == 'SUCCESS') {
deploy(targetHosts, projectDir, user, deployEnvList, appNames, nacosDataId, action)
}
}
}
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化