blob: d456db2bfcb6abbd97ae0f12fd9b93941f478ad7 [file] [log] [blame]
Jakub Josefc4064bb2017-04-03 19:25:19 +02001/**
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
14def common = new com.mirantis.mk.Common()
15def gerrit = new com.mirantis.mk.Gerrit()
16def dockerLib = new com.mirantis.mk.Docker()
17node("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") {
Jakub Josef37942b82017-04-06 17:34:25 +020027 common.infoMsg("Building docker image ${IMAGE_NAME}")
Jakub Josefc4064bb2017-04-03 19:25:19 +020028 dockerApp = dockerLib.buildDockerImage(IMAGE_NAME, "", "${workspace}/${DOCKERFILE_PATH}", imageTagsList[0])
29 if(!dockerApp){
30 throw new Exception("Docker build image failed")
31 }
32 }
33 stage("upload to docker hub"){
34 for(int i=0;i<imageTagsList.size();i++){
Jakub Josef37942b82017-04-06 17:34:25 +020035 common.infoMsg("Uploading image ${IMAGE_NAME} with tag ${imageTagsList[i]}")
Jakub Josefc4064bb2017-04-03 19:25:19 +020036 dockerApp.push(imageTagsList[i])
37 }
38 }
39 }
40 } catch (Throwable e) {
41 // If there was an error or exception thrown, the build failed
42 currentBuild.result = "FAILURE"
43 throw e
44 } finally {
45 common.sendNotification(currentBuild.result,"",["slack"])
46 }
47}