Merge "work with empty reclass"
diff --git a/docker-image-build-pipeline.groovy b/docker-image-build-pipeline.groovy
new file mode 100644
index 0000000..65bf1d0
--- /dev/null
+++ b/docker-image-build-pipeline.groovy
@@ -0,0 +1,45 @@
+/**
+ * Docker image build pipeline
+ * IMAGE_NAME - Image name
+ * IMAGE_GIT_URL - Image git repo URL
+ * IMAGE_BRANCH - Image repo branch
+ * IMAGE_CREDENTIALS_ID - Image repo credentials id
+ * IMAGE_TAGS - Image tags
+ * DOCKERFILE_PATH - Relative path to docker file in image repo
+ * REGISTRY_URL - Docker registry URL (can be empty)
+ * REGISTRY_CREDENTIALS_ID - Docker hub credentials id
+ *
+**/
+
+def common = new com.mirantis.mk.Common()
+def gerrit = new com.mirantis.mk.Gerrit()
+def dockerLib = new com.mirantis.mk.Docker()
+node("docker") {
+ def workspace = common.getWorkspace()
+ def imageTagsList = IMAGE_TAGS.tokenize(" ")
+ try{
+ def dockerApp
+ docker.withRegistry(REGISTRY_URL, REGISTRY_CREDENTIALS_ID) {
+ stage("checkout") {
+ gerrit.gerritPatchsetCheckout(IMAGE_GIT_URL, "", IMAGE_BRANCH, IMAGE_CREDENTIALS_ID)
+ }
+ stage("build") {
+ dockerApp = dockerLib.buildDockerImage(IMAGE_NAME, "", "${workspace}/${DOCKERFILE_PATH}", imageTagsList[0])
+ if(!dockerApp){
+ throw new Exception("Docker build image failed")
+ }
+ }
+ stage("upload to docker hub"){
+ for(int i=0;i<imageTagsList.size();i++){
+ dockerApp.push(imageTagsList[i])
+ }
+ }
+ }
+ } 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"])
+ }
+}
diff --git a/gating-pipeline.groovy b/gating-pipeline.groovy
index 8cc5031..bd94f63 100644
--- a/gating-pipeline.groovy
+++ b/gating-pipeline.groovy
@@ -4,14 +4,21 @@
* JOBS_NAMESPACE - Gerrit gating jobs namespace (mk, contrail, ...)
*
**/
+import groovy.json.JsonSlurper
def common = new com.mirantis.mk.Common()
def gerrit = new com.mirantis.mk.Gerrit()
def ssh = new com.mirantis.mk.Ssh()
node("python") {
try{
+ // test if change is not already merged
+ ssh.prepareSshAgentKey(CREDENTIALS_ID)
+ ssh.ensureKnownHosts(GERRIT_HOST)
+ def output = ssh.agentSh(String.format("ssh -p 29418 %s@%s gerrit query --format=JSON change:%s", GERRIT_NAME, GERRIT_HOST, GERRIT_CHANGE_NUMBER))
+ def jsonSlurper = new JsonSlurper()
+ def gerritChange = jsonSlurper.parseText(output)
stage("test") {
- if (!SKIP_TEST.equals("true")){
+ if (gerritChange.status != "MERGED" && !SKIP_TEST.equals("true")){
wrap([$class: 'AnsiColorBuildWrapper']) {
def gerritProjectArray = GERRIT_PROJECT.tokenize("/")
def gerritProject = gerritProjectArray[gerritProjectArray.size() - 1]
@@ -36,10 +43,12 @@
}
}
stage("submit review"){
- ssh.prepareSshAgentKey(CREDENTIALS_ID)
- ssh.ensureKnownHosts(GERRIT_HOST)
- ssh.agentSh(String.format("ssh -p 29418 %s@%s gerrit review --submit %s,%s", GERRIT_NAME, GERRIT_HOST, GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER))
- common.infoMsg(String.format("Gerrit review %s,%s submitted", GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER))
+ if(gerritChange.status == "MERGED"){
+ common.successMsg("Change ${GERRIT_CHANGE_NUMBER} is already merged, no need to gate them")
+ }else{
+ ssh.agentSh(String.format("ssh -p 29418 %s@%s gerrit review --submit %s,%s", GERRIT_NAME, GERRIT_HOST, GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER))
+ common.infoMsg(String.format("Gerrit review %s,%s submitted", GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER))
+ }
}
} catch (Throwable e) {
// If there was an error or exception thrown, the build failed