Ver código fonte

Актуализация

Tomishinets Vladimir 3 anos atrás
pai
commit
3b363d9356
1 arquivos alterados com 22 adições e 18 exclusões
  1. 22 18
      buildImage.Jenkinsfile

+ 22 - 18
buildImage.Jenkinsfile

@@ -13,19 +13,19 @@ pipeline {
     }
   }
   environment {
-    CLOUD='cloud-it-k8s'
+    CONTEXT='provision@sdsys.office'
     JENKINS_MAIL='jenkins.dev@sdsys.ru'
-    DOCKER_REGISTRY='jcr.infoclinica.ru'
-    DOCKER_IMAGE='lab/analis'
+    DOCKER_REGISTRY='images.sdsys.ru'
+    DOCKER_IMAGE='web-laboratory/analis'
     REPO='svn://192.168.21.250/programs/trunk/Services/Analis/Win32'
     HELM_GIT_URL='ssh://git@git.sdsys.ru:8022/labportal/k8s.git'
-    CHART_SUBPATH='helm/analis'
+    TAG=''
     SVN_DIR='analis'
     REV_NUMBER=''
-    PROJECT=''
     CHART_PATH=''
     HELM_DIR=''
-    TAG=''
+    IMAGE_TO_PUSH=''
+    VALUES_FILE =''
   }
   parameters {
     string(
@@ -43,23 +43,25 @@ pipeline {
     stage("SVN Checkout") {
       steps {
         script {
-          svnOps.checkout(REPO, SVN_DIR, REVNUM)
-          REV_NUMBER = svnOps.revNumber(SVN_DIR)
-          sh "echo 'REV_NUMBER = ${REV_NUMBER}'"
+          svnOps.checkout(REPO, REPO.split("/")[-2].toLowerCase(), REVNUM)
+          REV_NUMBER = svnOps.revNumber(REPO.split("/")[-2].toLowerCase())
+          echo "REV_NUMBER = ${REV_NUMBER}"
           gitOps.clone(HELM_GIT_URL)
           HELM_DIR = dirOps.calculateDir(HELM_GIT_URL)
-          PROJECT = DOCKER_IMAGE.split("/")[1]
-          CHART_PATH = "${HELM_DIR}/${CHART_SUBPATH}"
+          CHART_PATH = "helm/" + DOCKER_IMAGE.split("/")[0]
+          VALUES_FILE = HELM_DIR + "/helm/" + "dev-" + DOCKER_IMAGE.split("/")[1] + ".yaml
+          IMAGE_TO_PUSH = "${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${REV_NUMBER}-${BUILD_NUMBER}"
         }
       }
     }
     stage("Build Image") {
       steps {
         script {
-          echo "Build Image with Kaniko"
-          REGISTRY = "${DOCKER_REGISTRY}/${DOCKER_IMAGE}"
-          TAG = "${REV_NUMBER}-${BUILD_NUMBER}"
-          k8sBuildImage.kaniko(REGISTRY, TAG)
+          echo "Building ${IMAGE_TO_PUSH} with Kaniko"
+          k8sBuildImage.kaniko(IMAGE_TO_PUSH)
+          TAG = '${REV_NUMBER}-${BUILD_NUMBER}'
+          echo "Taging ${IMAGE_TO_PUSH} to latest"
+          k8sBuildImage.crane(IMAGE_TO_PUSH)
         }
       }
     }
@@ -67,10 +69,12 @@ pipeline {
       steps {
         script {
           echo "Update Helm Chart"
-          def data = readYaml file: "${CHART_PATH}/values.yaml"
-          TAG_PATH = "images.${PROJECT}.build"
+          def data = readYaml file: VALUES_FILE
+          TAG = "${REV_NUMBER}-${BUILD_NUMBER}"
+          TAG_PATH = "images." + DOCKER_IMAGE.split("/")[1] + ".build"
+          echo "Update ${TAG_PATH} to ${TAG} in ${VALUES_FILE}"
           yamlOps.updateBuilder(TAG_PATH, data, TAG)
-          writeYaml file: "${CHART_PATH}/values.yaml", data: data, overwrite: true
+          writeYaml file: "${VALUES_FILE}", data: data, overwrite: true
         }
       }
     }