Browse Source

See Redmine 117970

Владимир Томишинец 5 years ago
parent
commit
cb47c8cbf5
1 changed files with 30 additions and 22 deletions
  1. 30 22
      updateToTargetVersionJenkinsfile

+ 30 - 22
updateToTargetVersionJenkinsfile

@@ -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',
@@ -22,8 +25,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'
@@ -46,10 +47,13 @@ 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))}
+                 """
+            }
+          }
             sh "set +x && echo \"Update version of Apps to $toVersion\" > commit.txt"
           }
         }
@@ -82,7 +86,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"
@@ -100,10 +104,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"
+          }
         }
       }
     }
@@ -111,17 +117,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
+                 """
+            }
           }
         }
       }