Jakub Josef | c4064bb | 2017-04-03 19:25:19 +0200 | [diff] [blame] | 1 | /** |
| 2 | * Docker image build pipeline |
| 3 | * IMAGE_NAME - Image name |
| 4 | * IMAGE_GIT_URL - Image git repo URL |
| 5 | * IMAGE_BRANCH - Image repo branch |
| 6 | * IMAGE_CREDENTIALS_ID - Image repo credentials id |
| 7 | * IMAGE_TAGS - Image tags |
| 8 | * DOCKERFILE_PATH - Relative path to docker file in image repo |
| 9 | * REGISTRY_URL - Docker registry URL (can be empty) |
| 10 | * REGISTRY_CREDENTIALS_ID - Docker hub credentials id |
| 11 | * |
| 12 | **/ |
| 13 | |
| 14 | def common = new com.mirantis.mk.Common() |
| 15 | def gerrit = new com.mirantis.mk.Gerrit() |
| 16 | def dockerLib = new com.mirantis.mk.Docker() |
| 17 | node("docker") { |
| 18 | def workspace = common.getWorkspace() |
| 19 | def imageTagsList = IMAGE_TAGS.tokenize(" ") |
| 20 | try{ |
| 21 | def dockerApp |
| 22 | docker.withRegistry(REGISTRY_URL, REGISTRY_CREDENTIALS_ID) { |
| 23 | stage("checkout") { |
| 24 | gerrit.gerritPatchsetCheckout(IMAGE_GIT_URL, "", IMAGE_BRANCH, IMAGE_CREDENTIALS_ID) |
| 25 | } |
| 26 | stage("build") { |
| 27 | dockerApp = dockerLib.buildDockerImage(IMAGE_NAME, "", "${workspace}/${DOCKERFILE_PATH}", imageTagsList[0]) |
| 28 | if(!dockerApp){ |
| 29 | throw new Exception("Docker build image failed") |
| 30 | } |
| 31 | } |
| 32 | stage("upload to docker hub"){ |
| 33 | for(int i=0;i<imageTagsList.size();i++){ |
| 34 | dockerApp.push(imageTagsList[i]) |
| 35 | } |
| 36 | } |
| 37 | } |
| 38 | } catch (Throwable e) { |
| 39 | // If there was an error or exception thrown, the build failed |
| 40 | currentBuild.result = "FAILURE" |
| 41 | throw e |
| 42 | } finally { |
| 43 | common.sendNotification(currentBuild.result,"",["slack"]) |
| 44 | } |
| 45 | } |