blob: a22439aeeb2449f00946b2f388c24a972fdc46b4 [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{
Filip Pytloun8a3530b2017-06-30 17:28:37 +020022
23 def buildArgs = []
24 try {
Filip Pytlouncc3f8cf2017-06-30 17:52:33 +020025 buildArgs = IMAGE_BUILD_PARAMS.tokenize(' ')
Filip Pytloun8a3530b2017-06-30 17:28:37 +020026 } catch (Throwable e) {
27 buildArgs = []
28 }
Jakub Josefc4064bb2017-04-03 19:25:19 +020029 def dockerApp
30 docker.withRegistry(REGISTRY_URL, REGISTRY_CREDENTIALS_ID) {
31 stage("checkout") {
Filip Pytloun56070122017-06-29 15:30:15 +020032 git.checkoutGitRepository('.', IMAGE_GIT_URL, IMAGE_BRANCH, IMAGE_CREDENTIALS_ID)
Jakub Josefc4064bb2017-04-03 19:25:19 +020033 }
34 stage("build") {
Jakub Josef37942b82017-04-06 17:34:25 +020035 common.infoMsg("Building docker image ${IMAGE_NAME}")
Filip Pytloun8a3530b2017-06-30 17:28:37 +020036 dockerApp = dockerLib.buildDockerImage(IMAGE_NAME, "", "${workspace}/${DOCKERFILE_PATH}", imageTagsList[0], buildArgs)
Jakub Josefc4064bb2017-04-03 19:25:19 +020037 if(!dockerApp){
38 throw new Exception("Docker build image failed")
39 }
40 }
41 stage("upload to docker hub"){
42 for(int i=0;i<imageTagsList.size();i++){
Jakub Josef37942b82017-04-06 17:34:25 +020043 common.infoMsg("Uploading image ${IMAGE_NAME} with tag ${imageTagsList[i]}")
Jakub Josefc4064bb2017-04-03 19:25:19 +020044 dockerApp.push(imageTagsList[i])
45 }
46 }
47 }
48 } catch (Throwable e) {
49 // If there was an error or exception thrown, the build failed
50 currentBuild.result = "FAILURE"
51 throw e
52 } finally {
53 common.sendNotification(currentBuild.result,"",["slack"])
54 }
55}