Browse Source

fix: deploy/Jenkinsfile

李时威 9 tháng trước cách đây
mục cha
commit
9ba4528f68
1 tập tin đã thay đổi với 27 bổ sung6 xóa
  1. 27 6
      deploy/Jenkinsfile

+ 27 - 6
deploy/Jenkinsfile

@@ -8,11 +8,14 @@ pipeline {
 
   environment {
     IMAGE_REPO = "SXKJ:32775"
+    IMAGE_REPO_YILI = "registry.cn-hangzhou.aliyuncs.com/sxtest"
     TAB = "\n   \n  "
     GIT_LOG = sh (script: "git log --oneline -n 1", returnStdout: true).trim()
+    BUILD_USER_NAME = sh(script: "git log -1 --pretty=format:'%an'", returnStdout: true).trim()
     TITLE = "${JOB_BASE_NAME}-${ENV_APP}"
+    GIT_BRANCH_NAME = env.GIT_BRANCH.substring(env.GIT_BRANCH.lastIndexOf('/') + 1)
     TIMESTAMP = sh(returnStdout: true, script: "TZ=Asia/Shanghai date  +'%F_%H-%M-%S'").trim()
-    TAG = "${ENV_APP}-${TIMESTAMP}"
+    TAG = "${ENV_APP}-${GIT_BRANCH_NAME}-${TIMESTAMP}"
   }
   stages {
     stage('git-log') {
@@ -28,7 +31,13 @@ pipeline {
       steps {
         container('docker') {
           echo "构建 Docker 镜像阶段"
-          sh 'docker build  -t ${IMAGE_REPO}/${JOB_BASE_NAME}:${TAG} --output type=docker .'
+          sh '''
+          if [ "$ENV_APP" == "yiliocr-yn" ]; then
+            docker build  -t ${IMAGE_REPO}/${JOB_BASE_NAME}:${TAG} --output type=docker .
+          else
+            xxx
+          fi
+          '''
           echo "build success"
         }
         script {
@@ -40,7 +49,13 @@ pipeline {
       steps {
         container('docker') {
           echo "Push Docker 镜像阶段"
-          sh 'docker push ${IMAGE_REPO}/${JOB_BASE_NAME}:${TAG}'
+          sh '''
+          if [ "$ENV_APP" == "yiliocr-yn" ]; then
+            docker push ${IMAGE_REPO_YILI}/${JOB_BASE_NAME}:${TAG}
+          else
+            xxx
+          fi
+          '''
           echo "Push image success"
         }
         script {
@@ -51,7 +66,13 @@ pipeline {
     stage('重启服务') {
       steps {
         container('kubectl') {
-          sh '[[ "$ENV_APP" == "test" ]] && kubectl set image deployment/ocr-table table=${IMAGE_REPO}/${JOB_BASE_NAME}:${TAG} --namespace yili-ocr --kubeconfig kubeconfig-sxkj ||  kubectl set image deployment/ocr-table table=${IMAGE_REPO}/${JOB_BASE_NAME}:${TAG} --namespace yili-ocr  --kubeconfig kubeconfig-sxkjprod'
+          sh '''
+          if [ "$ENV_APP" == "yiliocr-yn" ]; then
+            echo "$ENV_APP"
+          else
+            xxx
+          fi
+          '''
         }
         script {
           env.BUILD_TASKS += env.STAGE_NAME + "✅" + env.TAB
@@ -70,7 +91,7 @@ pipeline {
                     "msgtype": "markdown",
                     "markdown": {
                         "title":"${TITLE}",
-                        "text": "😄👍 构建成功 👍😄  \n**项目名称**:${TITLE}  \n**Git log**: ${GIT_LOG}  \n**构建分支**: ${GIT_BRANCH}   \n**构建地址**:${BUILD_URL}  \n**构建任务**: ${BUILD_TASKS}"
+                        "text": "😄👍 构建成功 👍😄  \n**项目名称**:${TITLE}  \n**Git log**: ${GIT_LOG}   \n**构建者**: ${BUILD_USER_NAME}  \n**构建分支**: ${GIT_BRANCH}   \n**构建地址**:${BUILD_URL}  \n**构建任务**: ${BUILD_TASKS}"
                     }
                 }'
         """
@@ -84,7 +105,7 @@ pipeline {
                     "msgtype": "markdown",
                     "markdown": {
                         "title":"${TITLE}",
-                        "text": "😖❌ 构建失败 ❌😖  \n**项目名称**:${TITLE}  \n**Git log**: ${GIT_LOG}   \n**构建分支**: ${GIT_BRANCH}  \n**构建地址**:${BUILD_URL}  \n**构建任务**: ${BUILD_TASKS}"
+                        "text": "😖❌ 构建失败 ❌😖  \n**项目名称**:${TITLE}  \n**Git log**: ${GIT_LOG}   \n**构建者**: ${BUILD_USER_NAME}   \n**构建分支**: ${GIT_BRANCH}  \n**构建地址**:${BUILD_URL}  \n**构建任务**: ${BUILD_TASKS}"
                     }
                 }'
         """