blob: aff718f88336bece067dfec8c47b57c162aa25ac [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") {
Filip Pytlounade4e782017-06-29 14:50:47 +020024 checkout changelog: true, poll: false,
Filip Pytlouna814a152017-06-29 15:27:32 +020025 scm: [$class: 'GitSCM', branches: [[name:IMAGE_BRANCH]], doGenerateSubmoduleConfigurations: false,
Filip Pytlounade4e782017-06-29 14:50:47 +020026 extensions: [[$class: 'CleanCheckout']], submoduleCfg: [], userRemoteConfigs: [[credentialsId: IMAGE_CREDENTIALS_ID, url: IMAGE_GIT_URL]]]
Jakub Josefc4064bb2017-04-03 19:25:19 +020027 }
28 stage("build") {
Jakub Josef37942b82017-04-06 17:34:25 +020029 common.infoMsg("Building docker image ${IMAGE_NAME}")
Jakub Josefc4064bb2017-04-03 19:25:19 +020030 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 Josef37942b82017-04-06 17:34:25 +020037 common.infoMsg("Uploading image ${IMAGE_NAME} with tag ${imageTagsList[i]}")
Jakub Josefc4064bb2017-04-03 19:25:19 +020038 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}