Browse Source

See Redmine 117970

Владимир Томишинец 5 years ago
parent
commit
e7282387fe
1 changed files with 35 additions and 24 deletions
  1. 35 24
      updateVersionJenkinsfile

+ 35 - 24
updateVersionJenkinsfile

@@ -1,5 +1,8 @@
 def ENAMES = [ 'prod-open', 'prod' ]
 //def def ENAMES = [ 'dev-open', 'dev' ]
+def REPOS = ['prod': 'ssh://git@git.sdsys.ru:8022/labportal/stack-deploy.git',
+             'prod-open': 'ssh://git@git.sdsys.ru:8022/labportal/stack-deploy-open.git']
+def GIT_DIR = ['prod': 'stack-deploy', 'prod-open': 'stack-deploy-open']
 def CLUSTERS = ['prod': 'iru-swarm.infoclinica.lan',
                 'prod-open': 'iru-swarm1-open.infoclinica.ru',
                 'dev': 'dev-iru-swarm.infoclinica.lan',
@@ -23,8 +26,6 @@ pipeline {
     label "swarm"
   }
   environment {
-    SWARM_GIT_URL='ssh://git@git.sdsys.ru:8022/labportal/stack-deploy.git'
-    SWARM_GIT_NAME='stack-deploy'
     JENKINS_MAIL='jenkins.dev@sdsys.ru'
     DOCKER_CERT_PATH='/run/secrets/swarm'
     DOCKER_IMAGE='analis-wineservice'
@@ -47,18 +48,24 @@ pipeline {
     stage("Git Pull. Define Version to Update") {
       steps {
         script {
-          withCredentials([sshUserPrivateKey(credentialsId: 'provision', keyFileVariable: 'GIT_SSH_KEY', passphraseVariable: '', usernameVariable: 'GIT_SSH_USERNAME')]) {
-            sh """set +x && GIT_SSH_COMMAND='ssh -i ${GIT_SSH_KEY} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' \
-                    git clone ${SWARM_GIT_URL}
-               """
+          ENAMES.each { item ->
+            withCredentials([sshUserPrivateKey(credentialsId: 'provision', keyFileVariable: 'GIT_SSH_KEY', passphraseVariable: '', usernameVariable: 'GIT_SSH_USERNAME')]) {
+              sh """set +x && GIT_SSH_COMMAND='ssh -i ${GIT_SSH_KEY} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' \
+                    git clone ${REPOS.get((item))}
+                 """
+            }
           }
           switch (TASK_ACTION) {
             case 'up':
-              VERSION_TO_UPDATE = sh (script: "set +x && cat $SWARM_GIT_NAME/tags/lab/analis-wineservice.build-version" , returnStdout: true).trim()
+              ENAMES.each { item ->
+                VERSION_TO_UPDATE = sh (script: "set +x && cat ${GIT_DIR.get((item))}/tags/lab/analis-wineservice.build-version" , returnStdout: true).trim()
+              }
               sh "set +x && echo \"Update version of Apps to $VERSION_TO_UPDATE\" > commit.txt"
               break
             case 'down':
-              VERSION_TO_UPDATE = sh (script: "set +x && cat $SWARM_GIT_NAME/tags/lab/analis-wineservice.old-stable-version" , returnStdout: true).trim()
+              ENAMES.each { item ->
+                VERSION_TO_UPDATE = sh (script: "set +x && cat ${GIT_DIR.get((item))}/tags/lab/analis-wineservice.old-stable-version" , returnStdout: true).trim()
+              }
               sh "set +x && echo \"Downgrade version of Apps to $VERSION_TO_UPDATE\" > commit.txt"
               break
           }
@@ -99,7 +106,7 @@ pipeline {
               }
             }
             catch (err) {
-              def STABLE_VERSION = sh (script: "set +x && cat $SWARM_GIT_NAME/tags/lab/analis-wineservice.stable-version" , returnStdout: true).trim()
+              def STABLE_VERSION = sh (script: "set +x && cat ${GIT_DIR.get((item))}/tags/lab/analis-wineservice.stable-version" , returnStdout: true).trim()
               TO_ROLLBACK.each { target, value ->
                 for (service_name in value) {
                   echo "Recoverig $service_name running in $target to $STABLE_VERSION"
@@ -117,10 +124,12 @@ pipeline {
     stage("Update Tags") {
       steps {
         script {
-          def STABLE_VERSION = sh (script: "set +x && cat $SWARM_GIT_NAME/tags/lab/analis-wineservice.stable-version" , returnStdout: true).trim()
-          def OLD_STABLE_VERSION = sh (script: "set +x && cat $SWARM_GIT_NAME/tags/lab/analis-wineservice.old-stable-version" , returnStdout: true).trim()
-          sh "set +x && echo $STABLE_VERSION > $SWARM_GIT_NAME/tags/lab/analis-wineservice.old-stable-version"
-          sh "set +x && echo $VERSION_TO_UPDATE > $SWARM_GIT_NAME/tags/lab/analis-wineservice.stable-version" 
+          ENAMES.each { item ->
+            def STABLE_VERSION = sh (script: "set +x && cat ${GIT_DIR.get((item))}/tags/lab/analis-wineservice.stable-version" , returnStdout: true).trim()
+            def OLD_STABLE_VERSION = sh (script: "set +x && cat ${GIT_DIR.get((item))}/tags/lab/analis-wineservice.old-stable-version" , returnStdout: true).trim()
+            sh "set +x && echo $STABLE_VERSION > ${GIT_DIR.get((item))}/tags/lab/analis-wineservice.old-stable-version"
+            sh "set +x && echo $VERSION_TO_UPDATE > ${GIT_DIR.get((item))}/tags/lab/analis-wineservice.stable-version" 
+          }
         }
       }
     }
@@ -128,17 +137,19 @@ pipeline {
       steps {
         script {
           sh "cat commit.txt"
-          sh "cat $SWARM_GIT_NAME/tags/lab/analis-wineservice.stable-version"
-          sh "cat $SWARM_GIT_NAME/tags/lab/analis-wineservice.old-stable-version"
-          withCredentials([sshUserPrivateKey(credentialsId: 'provision', keyFileVariable: 'GIT_SSH_KEY', passphraseVariable: '', usernameVariable: 'GIT_SSH_USERNAME')]) {
-            sh """cd $SWARM_GIT_NAME
-                  git add -A
-                  git config --global user.email "${JENKINS_MAIL}"
-                  git config --global user.name "Jenkins"
-                  git commit -F ../commit.txt
-                  GIT_SSH_COMMAND='ssh -i ${GIT_SSH_KEY} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' \
-                  git push origin master
-               """
+          ENAMES.each { item ->
+            sh "cat ${GIT_DIR.get((item))}/tags/lab/analis-wineservice.stable-version"
+            sh "cat ${GIT_DIR.get((item))}/tags/lab/analis-wineservice.old-stable-version"
+            withCredentials([sshUserPrivateKey(credentialsId: 'provision', keyFileVariable: 'GIT_SSH_KEY', passphraseVariable: '', usernameVariable: 'GIT_SSH_USERNAME')]) {
+              sh """cd ${GIT_DIR.get((item))}
+                    git add -A
+                    git config --global user.email "${JENKINS_MAIL}"
+                    git config --global user.name "Jenkins"
+                    git commit -F ../commit.txt
+                    GIT_SSH_COMMAND='ssh -i ${GIT_SSH_KEY} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' \
+                    git push origin master
+                 """
+            }
           }
         }
       }