Jelajahi Sumber

Обновить 'Jenkinsfile'

Vladimir Tomishinets 6 tahun lalu
induk
melakukan
293e2aa9be
1 mengubah file dengan 34 tambahan dan 2 penghapusan
  1. 34 2
      Jenkinsfile

+ 34 - 2
Jenkinsfile

@@ -8,6 +8,8 @@ pipeline {
     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'
   }
   parameters {
     string(
@@ -46,11 +48,41 @@ pipeline {
           for (String item : service_update.split()) {
             try{
               echo "Updating $item"
-              sh "docker service update $item --image ${DOCKER_REGISTRY}/iru/${DOCKER_IMAGE}:${repo}-${BUILD_NUMBER}"
+              if (repo == 'prod') {
+                withEnv(["service_name=${item}"]) {
+                  sh '''export DOCKER_CERT_PATH=/run/secrets/swarm
+                        export DOCKER_HOST=tcp://${CLUSTER_PROD}:2376 DOCKER_TLS_VERIFY=1
+                        docker service update ${service_name} --image ${DOCKER_REGISTRY}/iru/${DOCKER_IMAGE}:${repo}-${BUILD_NUMBER}
+                      '''
+                }
+              }
+              if (repo == 'dev') {
+                withEnv(["service_name=${item}"]) {
+                  sh '''export DOCKER_CERT_PATH=/run/secrets/swarm
+                        export DOCKER_HOST=tcp://${CLUSTER_DEV}:2376 DOCKER_TLS_VERIFY=1
+                        docker service update ${service_name} --image ${DOCKER_REGISTRY}/iru/${DOCKER_IMAGE}:${repo}-${BUILD_NUMBER}
+                     '''
+                }
+              }
             }
             catch(err){
               echo "Recovering service $item"
-              sh "docker service rollback $item"
+              if (repo == 'prod') {
+                withEnv(["service_name=${item}"]) {
+                  sh '''export DOCKER_CERT_PATH=/run/secrets/swarm
+                        export DOCKER_HOST=tcp://${CLUSTER_PROD}:2376 DOCKER_TLS_VERIFY=1
+                        docker service rollback ${service_name}
+                     '''
+                }
+              }
+              if (repo == 'dev') {
+                withEnv(["service_name=${item}"]) {
+                  sh '''export DOCKER_CERT_PATH=/run/secrets/swarm
+                        export DOCKER_HOST=tcp://${CLUSTER_DEV}:2376 DOCKER_TLS_VERIFY=1
+                        docker service rollback ${service_name}
+                     '''
+                }
+              }
               throw err
             }
           }