From e1715c0f8ded84ddbba361baa6f6e81b0233f265 Mon Sep 17 00:00:00 2001 From: Geapefurit <670884108@qq.com> Date: Wed, 22 Nov 2023 16:21:32 +0800 Subject: [PATCH] checkout tag when deploy --- Jenkinsfile | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 3f2418ac..94d61c6b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -337,26 +337,50 @@ pipeline { } } - stage('Deploy for test or prod') { + stage('Deploy for test') { when { expression { DEPLOY_TARGET == 'true' } anyOf{ expression { TARGET_ENV ==~ /.*testing.*/ } - expression { TARGET_ENV ==~ /.*production.*/ } } } steps { sh(returnStdout: true, script: ''' - tag=latest set +e - result=$(echo $TARGET_ENV | grep "testing") + revlist=`git rev-list --tags --max-count=1` + rc=$? set -e - if [[ "$result" != "" ]] - then - tag=$(git tag|grep '[13579]$'|sort -V|tail -n 1| tr -d '\n') - else - tag=$(git tag|grep '[02468]$'|sort -V|tail -n 1| tr -d '\n') + if [ ! 0 -eq $rc ]; then + exit 0 fi + tag=`git describe --tags $revlist` + + git reset --hard + git checkout $tag + + export CLOUD_PROXY_DOMAIN=cloud-proxy.$ROOT_DOMAIN # for gateway + export CLOUD_PROXY_GRPC_PORT=$DOMAIN_HTTP_PORT # for gateway + export CLOUD_CERT_NAME=$CERT_NAME # for webui and dashboard + export CLOUD_ROOT_DOMAIN=$ROOT_DOMAIN # for webui and dashboard + TAG=$tag make deploy-to-k8s-cluster + '''.stripIndent()) + } + } + + stage('Deploy for prod') { + when { + expression { DEPLOY_TARGET == 'true' } + anyOf{ + expression { TARGET_ENV ==~ /.*testing.*/ } + expression { TARGET_ENV ==~ /.*production.*/ } + } + } + steps { + sh(returnStdout: true, script: ''' + tag=$(git tag|grep '[02468]$'|sort -V|tail -n 1| tr -d '\n') + + git reset --hard + git checkout $tag export CLOUD_PROXY_DOMAIN=cloud-proxy.$ROOT_DOMAIN # for gateway export CLOUD_PROXY_GRPC_PORT=$DOMAIN_HTTP_PORT # for gateway