Added pipelines previously defined in mk-ci-salt-model

Change-Id: Id759cf59d029b3d7d9e1fbd13abf875b6737ebc4
diff --git a/aptly-promote-pipeline.groovy b/aptly-promote-pipeline.groovy
new file mode 100644
index 0000000..6c84606
--- /dev/null
+++ b/aptly-promote-pipeline.groovy
@@ -0,0 +1,19 @@
+def common = new com.mirantis.mk.Common()
+def aptly = new com.mirantis.mk.Aptly()
+node() {
+  try{
+    stage("promote") {
+      lock("aptly-api") {
+        wrap([$class: 'AnsiColorBuildWrapper']) {
+          aptly.promotePublish(APTLY_URL, SOURCE, TARGET, RECREATE, null, null, DIFF_ONLY)
+        }
+      }
+    }
+  } catch (Throwable e) {
+     // If there was an error or exception thrown, the build failed
+     currentBuild.result = "FAILURE"
+     throw e
+  } finally {
+     common.sendNotification(currentBuild.result,"",["slack"])
+  }
+}
\ No newline at end of file
diff --git a/build-debian-packages.groovy b/build-debian-packages.groovy
new file mode 100644
index 0000000..58dfe57
--- /dev/null
+++ b/build-debian-packages.groovy
@@ -0,0 +1,95 @@
+def common = new com.mirantis.mk.Common()
+def aptly = new com.mirantis.mk.Aptly()
+def debian = new com.mirantis.mk.Debian()
+
+def snapshot
+try {
+  snapshot = DEBIAN_SNAPSHOT
+} catch (MissingPropertyException e) {
+  snapshot = false
+}
+def debian_branch
+try {
+  debian_branch = DEBIAN_BRANCH
+} catch (MissingPropertyException e) {
+  debian_branch = null
+}
+def revisionPostfix
+try {
+  revisionPostfix = REVISION_POSTFIX
+} catch (MissingPropertyException e) {
+  revisionPostfix = null
+}
+def timestamp = common.getDatetime()
+node("docker") {
+  try{
+    stage("checkout") {
+      sh("rm -rf src || true")
+      dir("src") {
+        def pollBranches = [[name:SOURCE_BRANCH]]
+        if (debian_branch) {
+          pollBranches.add([name:DEBIAN_BRANCH])
+        }
+        checkout changelog: true, poll: false,
+          scm: [$class: 'GitSCM', branches: pollBranches, doGenerateSubmoduleConfigurations: false,
+          extensions: [[$class: 'CleanCheckout']],  submoduleCfg: [], userRemoteConfigs: [[credentialsId: SOURCE_CREDENTIALS, url: SOURCE_URL]]]
+        if (debian_branch){
+          sh("git checkout "+DEBIAN_BRANCH)
+        }
+      }
+      debian.cleanup(OS+":"+DIST)
+    }
+    stage("build-source") {
+      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.*"
+    }
+    stage("build-binary") {
+      dsc = sh script: "ls build-area/*.dsc", returnStdout: true
+      debian.buildBinary(
+        dsc.trim(),
+        OS+":"+DIST,
+        EXTRA_REPO_URL,
+        EXTRA_REPO_KEY_URL
+      )
+      archiveArtifacts artifacts: "build-area/*.deb"
+    }
+    stage("lintian") {
+      changes = sh script: "ls build-area/*_"+ARCH+".changes", returnStdout: true
+      try {
+        debian.runLintian(changes.trim(), OS, OS+":"+DIST)
+      } catch (Exception e) {
+        println "[WARN] Lintian returned non-zero exit status"
+        currentBuild.result = 'UNSTABLE'
+      }
+    }
+    lock("aptly-api") {
+      stage("upload") {
+        buildSteps = [:]
+        debFiles = sh script: "ls build-area/*.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(
+                "build-area/"+fh.name,
+                APTLY_URL,
+                APTLY_REPO,
+                true
+            )
+        }
+        parallel buildSteps
+      }
+      stage("publish") {
+          aptly.snapshotRepo(APTLY_URL, APTLY_REPO, timestamp)
+          aptly.publish(APTLY_URL)
+      }
+    }
+  } catch (Throwable e) {
+     // If there was an error or exception thrown, the build failed
+     currentBuild.result = "FAILURE"
+     throw e
+  } finally {
+     common.sendNotification(currentBuild.result,"",["slack"])
+  }
+}
\ No newline at end of file
diff --git a/build-extra-dpdk-pipeline.groovy b/build-extra-dpdk-pipeline.groovy
new file mode 100644
index 0000000..fab87f7
--- /dev/null
+++ b/build-extra-dpdk-pipeline.groovy
@@ -0,0 +1,44 @@
+def common = new com.mirantis.mk.Common()
+def aptly = new com.mirantis.mk.Aptly()
+def timestamp = common.getDatetime()
+
+node("docker") {
+  try {
+    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
+    }
+    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"
+    }
+    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,
+                APTLY_URL,
+                APTLY_REPO,
+                true
+            )
+        }
+        parallel buildSteps
+      }
+      stage("publish") {
+          aptly.snapshotRepo(APTLY_URL, APTLY_REPO, timestamp)
+          aptly.publish(APTLY_URL)
+      }
+     }
+     } catch (Throwable e) {
+       // If there was an error or exception thrown, the build failed
+       currentBuild.result = "FAILURE"
+       throw e
+    } finally {
+       common.sendNotification(currentBuild.result,"",["slack"])
+    }
+}
\ No newline at end of file
diff --git a/git-mirror-2way-pipeline.groovy b/git-mirror-2way-pipeline.groovy
new file mode 100644
index 0000000..0b7e023
--- /dev/null
+++ b/git-mirror-2way-pipeline.groovy
@@ -0,0 +1,29 @@
+def common = new com.mirantis.mk.Common()
+stage("Mirror") {
+  node() {
+    try{
+      def branches = BRANCHES.tokenize(',')
+      def pollBranches = []
+      for (i=0; i < branches.size; i++) {
+          pollBranches.add([name:branches[i]])
+      }
+      dir("target") {
+        checkout changelog: true, poll: true,
+          scm: [$class: 'GitSCM', branches: pollBranches, doGenerateSubmoduleConfigurations: false, submoduleCfg: [],
+          extensions: [[$class: 'CleanCheckout']], submoduleCfg: [], userRemoteConfigs: [[credentialsId: CREDENTIALS_ID, url: TARGET_URL]]]
+      }
+      dir("source") {
+        checkout changelog: true, poll: true,
+          scm: [$class: 'GitSCM', branches: pollBranches, doGenerateSubmoduleConfigurations: false,
+          extensions: [[$class: 'CleanCheckout']],  submoduleCfg: [], userRemoteConfigs: [[credentialsId: CREDENTIALS_ID, url: SOURCE_URL]]]
+        common.mirrorGit(SOURCE_URL, TARGET_URL, CREDENTIALS_ID, BRANCHES, true, true, false)
+      }
+    } catch (Throwable e) {
+       // If there was an error or exception thrown, the build failed
+       currentBuild.result = "FAILURE"
+       throw e
+    } finally {
+       common.sendNotification(currentBuild.result,"",["slack"])
+    }
+  }
+}
\ No newline at end of file
diff --git a/git-mirror-pipeline.groovy b/git-mirror-pipeline.groovy
new file mode 100644
index 0000000..9da9813
--- /dev/null
+++ b/git-mirror-pipeline.groovy
@@ -0,0 +1,24 @@
+def common = new com.mirantis.mk.Common()
+stage("Mirror") {
+  node() {
+    try{
+      def branches = BRANCHES.tokenize(',')
+      def pollBranches = []
+      for (i=0; i < branches.size; i++) {
+          pollBranches.add([name:branches[i]])
+      }
+      dir("source") {
+        checkout changelog: true, poll: true,
+          scm: [$class: 'GitSCM', branches: pollBranches, doGenerateSubmoduleConfigurations: false, submoduleCfg: [], 
+          extensions: [[$class: 'CleanCheckout']], submoduleCfg: [], userRemoteConfigs: [[credentialsId: CREDENTIALS_ID, url: SOURCE_URL]]]
+        common.mirrorGit(SOURCE_URL, TARGET_URL, CREDENTIALS_ID, BRANCHES)
+      }
+    } catch (Throwable e) {
+       // If there was an error or exception thrown, the build failed
+       currentBuild.result = "FAILURE"
+       throw e
+    } finally {
+       common.sendNotification(currentBuild.result,"",["slack"])
+    }
+  }
+}
\ No newline at end of file
diff --git a/release-salt-formulas-pipeline.groovy b/release-salt-formulas-pipeline.groovy
new file mode 100644
index 0000000..90ce9ef
--- /dev/null
+++ b/release-salt-formulas-pipeline.groovy
@@ -0,0 +1,30 @@
+def common = new com.mirantis.mk.Common()
+node() {
+  try{
+    stage("checkout") {
+      dir("src") {
+        common.prepareSshAgentKey(CREDENTIALS_ID)
+        common.ensureKnownHosts(SOURCE_URL)
+        git url: SOURCE_URL, branch: "master", credentialsId: CREDENTIALS_ID, poll: false
+        sh("git branch --set-upstream-to=origin/master")
+        common.agentSh("make update")
+      }
+    }
+    stage("tag") {
+      dir("src/formulas") {
+        sh("for i in *; do cd \$i; git remote | grep gerrit || git remote add gerrit $GERRIT_BASE/\$i; git config user.name Jenkins; git config user.email autobuild@mirantis.com; git tag -m $TAG $TAG; cd ..; done")
+      }
+    }
+    stage("push") {
+      dir("src/formulas") {
+        common.agentSh("mr --trust-all -j4 --force run git push gerrit $TAG")
+      }
+    }
+  } catch (Throwable e) {
+     // If there was an error or exception thrown, the build failed
+     currentBuild.result = "FAILURE"
+     throw e
+  } finally {
+     common.sendNotification(currentBuild.result,"",["slack"])
+  }
+}
\ No newline at end of file
diff --git a/test-salt-formulas-pipeline.groovy b/test-salt-formulas-pipeline.groovy
new file mode 100644
index 0000000..2a3b2ac
--- /dev/null
+++ b/test-salt-formulas-pipeline.groovy
@@ -0,0 +1,23 @@
+def common = new com.mirantis.mk.Common()
+def gerrit = new com.mirantis.mk.Gerrit()
+node("python") {
+  try{
+    stage("checkout") {
+      gerrit.gerritPatchsetCheckout ([
+          credentialsId : CREDENTIALS_ID
+      ])
+    }
+    stage("test") {
+      wrap([$class: 'AnsiColorBuildWrapper']) {
+        sh("make clean")
+        sh("[ $SALT_VERSION != 'latest' ] || export SALT_VERSION=''; make test")
+      }
+    }
+  } catch (Throwable e) {
+     // If there was an error or exception thrown, the build failed
+     currentBuild.result = "FAILURE"
+     throw e
+  } finally {
+     common.sendNotification(currentBuild.result,"",["slack"])
+  }
+}
\ No newline at end of file
diff --git a/test-salt-models-pipeline.groovy b/test-salt-models-pipeline.groovy
new file mode 100644
index 0000000..ebc99c9
--- /dev/null
+++ b/test-salt-models-pipeline.groovy
@@ -0,0 +1,24 @@
+def common = new com.mirantis.mk.Common()
+def gerrit = new com.mirantis.mk.Gerrit()
+
+node("python") {
+  try{
+    stage("checkout") {
+      gerrit.gerritPatchsetCheckout ([
+          credentialsId : CREDENTIALS_ID
+      ])
+      sh("git submodule init; git submodule sync; git submodule update --recursive")
+    }
+    stage("test") {
+      wrap([$class: 'AnsiColorBuildWrapper']) {
+        sh("make test")
+      }
+    }
+  } catch (Throwable e) {
+     // If there was an error or exception thrown, the build failed
+     currentBuild.result = "FAILURE"
+     throw e
+  } finally {
+     common.sendNotification(currentBuild.result,"",["slack"])
+  }
+}
\ No newline at end of file