Merge "update pipeline for oc4 upgrade"
diff --git a/build-debian-packages-pipeline.groovy b/build-debian-packages-pipeline.groovy
index 0d9839f..4220b7a 100644
--- a/build-debian-packages-pipeline.groovy
+++ b/build-debian-packages-pipeline.groovy
@@ -52,9 +52,17 @@
         if (debian_branch) {
           pollBranches.add([name:DEBIAN_BRANCH])
         }
+        def extensions = [[$class: 'CleanCheckout']]
+        def userRemoteConfigs = [[credentialsId: SOURCE_CREDENTIALS, url: SOURCE_URL]]
+        // Checkout specified refspec to local branch
+        if (common.validInputParam('SOURCE_REFSPEC')) {
+          extensions.add([$class: 'BuildChooserSetting', buildChooser: [$class: 'GerritTriggerBuildChooser']])
+          extensions.add([$class: 'LocalBranch', localBranch: SOURCE_BRANCH])
+          userRemoteConfigs[0]['refspec'] = SOURCE_REFSPEC
+        }
         checkout changelog: true, poll: false,
           scm: [$class: 'GitSCM', branches: pollBranches, doGenerateSubmoduleConfigurations: false,
-          extensions: [[$class: 'CleanCheckout']],  submoduleCfg: [], userRemoteConfigs: [[credentialsId: SOURCE_CREDENTIALS, url: SOURCE_URL]]]
+          extensions: extensions,  submoduleCfg: [], userRemoteConfigs: userRemoteConfigs]
         if (debian_branch){
           sh("git checkout "+DEBIAN_BRANCH)
         }
@@ -62,7 +70,12 @@
       debian.cleanup(OS+":"+DIST)
     }
     stage("build-source") {
-      debian.buildSource("src", OS+":"+DIST, snapshot, 'Jenkins', 'autobuild@mirantis.com', revisionPostfix)
+      // If SOURCE_REFSPEC is defined refspec will be checked out to local branch and need to build it instead of origin branch.
+      if (common.validInputParam('SOURCE_REFSPEC')) {
+        debian.buildSource("src", OS+":"+DIST, snapshot, 'Jenkins', 'autobuild@mirantis.com', revisionPostfix, '')
+      } else {
+        debian.buildSource("src", OS+":"+DIST, snapshot, 'Jenkins', 'autobuild@mirantis.com', revisionPostfix)
+      }
       archiveArtifacts artifacts: "build-area/*.dsc"
       archiveArtifacts artifacts: "build-area/*_source.changes"
       archiveArtifacts artifacts: "build-area/*.tar.*"
diff --git a/cloud-deploy-pipeline.groovy b/cloud-deploy-pipeline.groovy
index 74d7cde..4b25488 100644
--- a/cloud-deploy-pipeline.groovy
+++ b/cloud-deploy-pipeline.groovy
@@ -296,26 +296,6 @@
             }
         }
 
-        // install ceph
-        if (common.checkContains('STACK_INSTALL', 'ceph')) {
-            stage('Install Ceph MONs') {
-                orchestrate.installCephMon(venvPepper)
-            }
-
-            stage('Install Ceph OSDs') {
-                orchestrate.installCephOsd(venvPepper)
-            }
-
-
-            stage('Install Ceph clients') {
-                orchestrate.installCephClient(venvPepper)
-            }
-
-            stage('Connect Ceph') {
-                orchestrate.connectCeph(venvPepper)
-            }
-        }
-
         // install k8s
         if (common.checkContains('STACK_INSTALL', 'k8s')) {
 
@@ -421,6 +401,26 @@
 
         }
 
+        // install ceph
+        if (common.checkContains('STACK_INSTALL', 'ceph')) {
+            stage('Install Ceph MONs') {
+                orchestrate.installCephMon(venvPepper)
+            }
+
+            stage('Install Ceph OSDs') {
+                orchestrate.installCephOsd(venvPepper)
+            }
+
+
+            stage('Install Ceph clients') {
+                orchestrate.installCephClient(venvPepper)
+            }
+
+            stage('Connect Ceph') {
+                orchestrate.connectCeph(venvPepper)
+            }
+        }
+
         if (common.checkContains('STACK_INSTALL', 'oss')) {
           stage('Install Oss infra') {
             orchestrate.installOssInfra(venvPepper)
diff --git a/docker-build-image-pipeline.groovy b/docker-build-image-pipeline.groovy
index 926fd88..cb0e3f9 100644
--- a/docker-build-image-pipeline.groovy
+++ b/docker-build-image-pipeline.groovy
@@ -38,8 +38,9 @@
           def revision = sh(script: "git describe --tags --abbrev=4 | grep -oP \"^${tag}-\\K.*\" | awk -F\\- '{print \$1}'", returnStdout: true).trim()
           imageTagsList << tag
           revision = revision ? revision : "0"
-          imageTagsList << "${tag}-${revision}"
-
+          if(Integer.valueOf(revision) > 0){
+            imageTagsList << "${tag}-${revision}"
+          }
           if (!imageTagsList.contains("latest")) {
             imageTagsList << "latest"
           }