Add docker image build pipeline
Change-Id: Icd8c4c0eba3b5de2500404852a6c2b2443b1af91
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"])
+ }
+}