blob: 97c4f28e8d0be2489be1e3b907397298ed962107 [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()
Filip Pytloun56070122017-06-29 15:30:15 +020016def git = new com.mirantis.mk.Git()
Jakub Josefc4064bb2017-04-03 19:25:19 +020017def dockerLib = new com.mirantis.mk.Docker()
18node("docker") {
19 def workspace = common.getWorkspace()
20 def imageTagsList = IMAGE_TAGS.tokenize(" ")
21 try{
22 def dockerApp
23 docker.withRegistry(REGISTRY_URL, REGISTRY_CREDENTIALS_ID) {
24 stage("checkout") {
Filip Pytloun56070122017-06-29 15:30:15 +020025 git.checkoutGitRepository('.', IMAGE_GIT_URL, IMAGE_BRANCH, IMAGE_CREDENTIALS_ID)
Jakub Josefc4064bb2017-04-03 19:25:19 +020026 }
27 stage("build") {
Jakub Josef37942b82017-04-06 17:34:25 +020028 common.infoMsg("Building docker image ${IMAGE_NAME}")
Jakub Josefc4064bb2017-04-03 19:25:19 +020029 dockerApp = dockerLib.buildDockerImage(IMAGE_NAME, "", "${workspace}/${DOCKERFILE_PATH}", imageTagsList[0])
30 if(!dockerApp){
31 throw new Exception("Docker build image failed")
32 }
33 }
34 stage("upload to docker hub"){
35 for(int i=0;i<imageTagsList.size();i++){
Jakub Josef37942b82017-04-06 17:34:25 +020036 common.infoMsg("Uploading image ${IMAGE_NAME} with tag ${imageTagsList[i]}")
Jakub Josefc4064bb2017-04-03 19:25:19 +020037 dockerApp.push(imageTagsList[i])
38 }
39 }
40 }
41 } catch (Throwable e) {
42 // If there was an error or exception thrown, the build failed
43 currentBuild.result = "FAILURE"
44 throw e
45 } finally {
46 common.sendNotification(currentBuild.result,"",["slack"])
47 }
48}