Vadim Surkov преди 6 години
родител
ревизия
3e94e6f832
променени са 1 файла, в които са добавени 31 реда и са изтрити 8 реда
  1. 31 8
      Jenkinsfile

+ 31 - 8
Jenkinsfile

@@ -3,24 +3,29 @@ pipeline {
     label "swarm"
   }
   environment {
-    DOCKER_REGISTRY='dev-registry.infoclinica.ru:5000'
     DOCKER_IMAGE='node'
     SWARM_GIT_URL='ssh://git@git.sdsys.ru:8022/iru/stack-deploy.git'
     SWARM_GIT_NAME='stack-deploy'
     JENKINS_MAIL='jenkins@sdsys.ru'
     CLUSTER_DEV='dev-iru-swarm.infoclinica.lan'
     CLUSTER_PROD='iru-swarm.infoclinica.ru'
+    PACKAGE_NAME='web-registry-portal'
+    DEV_REGISTRY='dev-registry.infoclinica.ru:5000'
+    PROD_REGISTRY='registry.infoclinica.ru:5000'
+    DOCKER_CERT_PATH='/run/secrets/swarm'
+    DOCKER_HOST=''
+    DOCKER_REGISTRY=''
   }
   parameters {
     string(
       name: "repo",
       defaultValue: "prod",
-      description: "Repository to build and/or deploy from."
+      description: "Repository to build and/or deploy from. Values - dev, prod."
     )
     string(
       name: "cluster",
       defaultValue: "dev",
-      description: "Cluster to deploy (dev or prod)."
+      description: "Cluster to deploy. Values - dev, prod."
     )
     string(
       name: "service_update",
@@ -36,17 +41,35 @@ pipeline {
   stages {
     stage("Build") {
       steps {
-        echo "Building ${DOCKER_REGISTRY}/iru/${DOCKER_IMAGE}:${repo}-${BUILD_NUMBER}."
+        script {
+          switch (cluster) {
+             case 'prod':
+                DOCKER_REGISTRY=PROD_REGISTRY
+                DOCKER_HOST="tcp://${CLUSTER_PROD}:2376 DOCKER_TLS_VERIFY=1"
+                break
+             case 'dev':
+                DOCKER_REGISTRY=DEV_REGISTRY
+                DOCKER_HOST="tcp://${CLUSTER_DEV}:2376 DOCKER_TLS_VERIFY=1"
+                break
+             default:
+                currentBuild.result = 'ABORTED'
+                error('Unknown cluster')
+          }
+        }
+        echo "Docker ${DOCKER_HOST}, Registry ${DOCKER_REGISTRY}"
+/*        echo "Building ${DOCKER_REGISTRY}/iru/${DOCKER_IMAGE}:${repo}-${BUILD_NUMBER}."
         sh "docker build --build-arg repo=${repo} --no-cache -t ${DOCKER_REGISTRY}/iru/${DOCKER_IMAGE}:${repo}-${BUILD_NUMBER} ."
-      }
+*/      }
     }
     stage("Publish") {
       steps {
-        echo "Publishing ${DOCKER_REGISTRY}/iru/${DOCKER_IMAGE}:${repo}-${BUILD_NUMBER}"
+/*        echo "Publishing ${DOCKER_REGISTRY}/iru/${DOCKER_IMAGE}:${repo}-${BUILD_NUMBER}"
         sh "docker push ${DOCKER_REGISTRY}/iru/${DOCKER_IMAGE}:${repo}-${BUILD_NUMBER}"
+*/    script {
+           sh "echo Building ${DOCKER_REGISTRY}/iru/${DOCKER_IMAGE}:${repo}-${BUILD_NUMBER}."
       }
     }
-    stage("Update") {
+/*    stage("Update") {
       when { expression { service_update != "" } }
       steps {
         script {
@@ -115,7 +138,7 @@ pipeline {
         }
       }
     }
-  }
+*/  }
   post {
     always {
       echo "CleaningUp work diretory"