Merge "Fixed credentials issue in system reclass test job"
diff --git a/build-debian-packages-pipeline.groovy b/build-debian-packages-pipeline.groovy
index 83a23fe..8536b5e 100644
--- a/build-debian-packages-pipeline.groovy
+++ b/build-debian-packages-pipeline.groovy
@@ -23,14 +23,14 @@
 
 def uploadPpa
 try {
-  uploadPpa = UPLOAD_PPA
+  uploadPpa = UPLOAD_PPA.toBoolean()
 } catch (MissingPropertyException e) {
   uploadPpa = null
 }
 
 def uploadAptly
 try {
-  uploadAptly = UPLOAD_APTLY
+  uploadAptly = UPLOAD_APTLY.toBoolean()
 } catch (MissingPropertyException e) {
   uploadAptly = true
 }
diff --git a/build-extra-dpdk-pipeline.groovy b/build-extra-dpdk-pipeline.groovy
index fab87f7..39928dc 100644
--- a/build-extra-dpdk-pipeline.groovy
+++ b/build-extra-dpdk-pipeline.groovy
@@ -1,24 +1,46 @@
 def common = new com.mirantis.mk.Common()
 def aptly = new com.mirantis.mk.Aptly()
+def git = new com.mirantis.mk.Git()
 def timestamp = common.getDatetime()
 
+def binaryPackages
+try {
+  binaryPackages = BINARY_PACKAGES
+} catch (MissingPropertyException e) {
+  binaryPackages = ""
+}
+
 node("docker") {
   try {
+    def workspace = common.getWorkspace()
     stage("checkout") {
       sh("test -d debs && rm -rf debs || true")
       sh("test -d build && rm -rf build || true")
-      git poll: false, url: SOURCE_URL, branch: SOURCE_BRANCH, credentialsId: SOURCE_CREDENTIALS
+      git.checkoutGitRepository(
+                            ".",
+                            SOURCE_URL,
+                            SOURCE_BRANCH,
+                            SOURCE_CREDENTIALS,
+                            false,
+                            30,
+                            1
+                        )
     }
     stage("build") {
-      sh("docker run -v "+common.getWorkspace()+":"+common.getWorkspace()+" -w "+common.getWorkspace()+" --rm=true --privileged "+OS+":"+DIST+" /bin/bash -c 'apt-get update && apt-get install -y packaging-dev && ./build-debs.sh "+DIST+"'")
-      archiveArtifacts artifacts: "debs/"+DIST+"-"+ARCH+"/*.deb"
+      if (binaryPackages == "all" || binaryPackages == "") {
+        sh("docker run -v " + workspace + ":" + workspace + " -w " + workspace + " --rm=true --privileged "+OS+":" + DIST +
+            " /bin/bash -c 'apt-get update && apt-get install -y packaging-dev && ./build-debs.sh " + DIST + "'")
+      } else {
+        sh("docker run -v " + workspace + ":" + workspace + " -w " + workspace + " --rm=true --privileged "+OS+":" + DIST +
+            " /bin/bash -c 'apt-get update && apt-get install -y packaging-dev && ./build-debs.sh " + DIST + " " + binaryPackages + "'")
+      }
+      archiveArtifacts artifacts: "debs/${DIST}-${ARCH}/*.deb"
     }
     lock("aptly-api") {
       stage("upload") {
         buildSteps = [:]
         debFiles = sh script: "ls debs/"+DIST+"-"+ARCH+"/*.deb", returnStdout: true
         for (file in debFiles.tokenize()) {
-            workspace = common.getWorkspace()
             def fh = new File((workspace+"/"+file).trim())
             buildSteps[fh.name.split('_')[0]] = aptly.uploadPackageStep(
                 "debs/"+DIST+"-"+ARCH+"/"+fh.name,
diff --git a/generate-cookiecutter-products.groovy b/generate-cookiecutter-products.groovy
index d836afb..0986c4e 100644
--- a/generate-cookiecutter-products.groovy
+++ b/generate-cookiecutter-products.groovy
@@ -43,7 +43,9 @@
             }
 
             stage ('Download full Reclass model') {
-                git.checkoutGitRepository(modelEnv, RECLASS_MODEL_URL, RECLASS_MODEL_BRANCH, RECLASS_MODEL_CREDENTIALS)
+                if (RECLASS_MODEL_URL != '') {
+                    git.checkoutGitRepository(modelEnv, RECLASS_MODEL_URL, RECLASS_MODEL_BRANCH, RECLASS_MODEL_CREDENTIALS)
+                }
             }
 
             stage('Generate base infrastructure') {
@@ -124,17 +126,19 @@
             name: cfg01
             domain: ${clusterDomain}
 """
+                sh "mkdir -p ${modelEnv}/nodes/"
                 writeFile(file: nodeFile, text: nodeString)
             }
 
             stage('Inject changes to Reclass model') {
-                git.changeGitBranch(modelEnv, targetBranch)
                 def outputSource = "${env.WORKSPACE}/template/output/"
+                sh "mkdir -p ${outputDestination}"
                 sh(returnStdout: true, script: "cp -vr ${outputSource} ${outputDestination}")
             }
 
             stage ('Save changes to Reclass model') {
                 if (COMMIT_CHANGES.toBoolean()) {
+                    git.changeGitBranch(modelEnv, targetBranch)
                     git.commitGitChanges(modelEnv, "Added new cluster ${clusterName}")
                     git.pushGitChanges(modelEnv, targetBranch, 'origin', RECLASS_MODEL_CREDENTIALS)
                 }
diff --git a/update-package.groovy b/update-package.groovy
index 9441751..1dd6e02 100644
--- a/update-package.groovy
+++ b/update-package.groovy
@@ -35,13 +35,18 @@
 
         stage('List target servers') {
             minions = salt.getMinions(saltMaster, targetAll)
+
+            if (minions.isEmpty()) {
+                throw new Exception("No minion was targeted")
+            }
+
             if (TARGET_SUBSET_TEST != "") {
                 targetTestSubset = minions.subList(0, Integer.valueOf(TARGET_SUBSET_TEST)).join(' or ')
-            }
-            else {
+            } else {
                 targetTestSubset = minions.join(' or ')
             }
             targetLiveSubset = minions.subList(0, Integer.valueOf(TARGET_SUBSET_LIVE)).join(' or ')
+
             targetLiveAll = minions.join(' or ')
             common.infoMsg("Found nodes: ${targetLiveAll}")
             common.infoMsg("Selected test nodes: ${targetTestSubset}")