长马测试环境jenkins多分支流水线部署模板

pipeline {

agent{
label "app02"
}

tools{
jdk "jdk1.8.0_341"
}

environment {
BUILD_TAG = "${new Date().format('yyyyMMddHHmmss')}-${env.BUILD_NUMBER}"
WORKSPACE = "/data/jenkins_home/workspace/chana-mazda-test-app02"
}

parameters {
gitParameter branchFilter: 'origin/(.*)', defaultValue: 'develop', name: 'BRANCH', type: 'PT_BRANCH'
}
stages {
stage('拉取代码') {
steps{
git branch: "${params.BRANCH}", credentialsId: '709e0d47-6fec-40f1-b10b-a2f7dc091c0c',url: 'https://gitee.com/wuhan_rui_yi_zhixiang/chana-mazda-prod.git'
echo '---This is a Checkout step---'
}
}

stage('Docker构建') {
steps {
echo '---This is a Build step---'
sh '''
source /etc/profile >/dev/null 2>&1
if [[ ${ACTION} = Deploy ]]; then
source /etc/profile >/dev/null 2>&1
cd ${WORKSPACE}


case ${SERVICES} in
api-gateway)
mvn clean install -T 8C -Dmaven.test.skip=true -Dmaven.compile.fork=true
cd ${WORKSPACE}/${SERVICES}
mvn docker:build
docker tag cmaharbor.zlx.com/cma-app-test/${SERVICES}:latest 172.31.0.3:18080/cma-app-test/${SERVICES}:${BUILD_TAG}
if [[ ${OPTION} =~ yes ]]; then
docker push 172.31.0.3:18080/cma-app-test/${SERVICES}:${BUILD_TAG}
fi
;;
auth-server)

cd ${WORKSPACE}/auth-center/${SERVICES}
mvn clean install -Dmaven.test.skip=true

mvn docker:build
docker tag cmaharbor.zlx.com/cma-app-test/${SERVICES}:latest 172.31.0.3:18080/cma-app-test/${SERVICES}:${BUILD_TAG}
if [[ ${OPTION} =~ yes ]]; then
docker push 172.31.0.3:18080/cma-app-test/${SERVICES}:${BUILD_TAG}
fi
;;

*)
mvn clean install -pl /business-center/${SERVICES} -am -Dmaven.test.skip=true
cd ${WORKSPACE}/business-center/${SERVICES}
mvn docker:build
docker tag cmaharbor.zlx.com/cma-app-test/${SERVICES}:latest 172.31.0.3:18080/cma-app-test/${SERVICES}:${BUILD_TAG}
if [[ ${OPTION} =~ yes ]]; then
docker push 172.31.0.3:18080/cma-app-test/${SERVICES}:${BUILD_TAG}
fi
esac
fi
'''
}
}

stage('部署发布') {
steps{
sh '''
if [[ ${ACTION} = Deploy ]]; then
sh /chana-mazda/deploy_start.sh ${SERVICES} ${BUILD_TAG}
echo "Deploy_SERVICES-------------${SERVICES}"
elif [[ ${ACTION} = RollBack ]]; then
RollBack_Version=$(echo ${OPTION}|sed 's/,/ /g')
sh /chana-mazda/deploy_start.sh ${SERVICES} ${RollBack_Version}
echo "RollBack_SERVICES-------------${SERVICES}"
else
docker restart ${SERVICES}
fi
'''
}
}
}


post {
always {
script {
// 添加信息型徽标
//addShortText text:'添加信息型徽标.'
manager.addShortText("${ACTION},${SERVICES},${BRANCH}分支,镜像${BUILD_TAG}")
}
}
}
}

posted @ 2024-11-05 13:33  追梦boyaaa  阅读(3)  评论(0编辑  收藏  举报