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") { |
Filip Pytloun | ade4e78 | 2017-06-29 14:50:47 +0200 | [diff] [blame] | 24 | checkout changelog: true, poll: false, |
Filip Pytloun | a814a15 | 2017-06-29 15:27:32 +0200 | [diff] [blame^] | 25 | scm: [$class: 'GitSCM', branches: [[name:IMAGE_BRANCH]], doGenerateSubmoduleConfigurations: false, |
Filip Pytloun | ade4e78 | 2017-06-29 14:50:47 +0200 | [diff] [blame] | 26 | extensions: [[$class: 'CleanCheckout']], submoduleCfg: [], userRemoteConfigs: [[credentialsId: IMAGE_CREDENTIALS_ID, url: IMAGE_GIT_URL]]] |
Jakub Josef | c4064bb | 2017-04-03 19:25:19 +0200 | [diff] [blame] | 27 | } |
| 28 | stage("build") { |
Jakub Josef | 37942b8 | 2017-04-06 17:34:25 +0200 | [diff] [blame] | 29 | common.infoMsg("Building docker image ${IMAGE_NAME}") |
Jakub Josef | c4064bb | 2017-04-03 19:25:19 +0200 | [diff] [blame] | 30 | dockerApp = dockerLib.buildDockerImage(IMAGE_NAME, "", "${workspace}/${DOCKERFILE_PATH}", imageTagsList[0]) |
| 31 | if(!dockerApp){ |
| 32 | throw new Exception("Docker build image failed") |
| 33 | } |
| 34 | } |
| 35 | stage("upload to docker hub"){ |
| 36 | for(int i=0;i<imageTagsList.size();i++){ |
Jakub Josef | 37942b8 | 2017-04-06 17:34:25 +0200 | [diff] [blame] | 37 | common.infoMsg("Uploading image ${IMAGE_NAME} with tag ${imageTagsList[i]}") |
Jakub Josef | c4064bb | 2017-04-03 19:25:19 +0200 | [diff] [blame] | 38 | dockerApp.push(imageTagsList[i]) |
| 39 | } |
| 40 | } |
| 41 | } |
| 42 | } catch (Throwable e) { |
| 43 | // If there was an error or exception thrown, the build failed |
| 44 | currentBuild.result = "FAILURE" |
| 45 | throw e |
| 46 | } finally { |
| 47 | common.sendNotification(currentBuild.result,"",["slack"]) |
| 48 | } |
| 49 | } |