-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathJenkinsfile
76 lines (72 loc) · 2.88 KB
/
Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/**
* Docker Aptly image build pipeline
*
* IMAGE_GIT_URL - Image git repo URL
* IMAGE_BRANCH - Image repo branch
* IMAGE_CREDENTIALS_ID - Image repo credentials id
* IMAGE_TAGS - Image tags
* REGISTRY_URL - Docker registry URL (can be empty)
* REGISTRY_CREDENTIALS_ID - Docker hub credentials id
*
**/
def common = new com.mirantis.mk.Common()
def gerrit = new com.mirantis.mk.Gerrit()
def dockerLib = new com.mirantis.mk.Docker()
node("docker") {
def workspace = common.getWorkspace()
def imageTagsList = IMAGE_TAGS.tokenize(" ")
try{
def aptly, aptlyApi, aptlyPublisher, aptlyPublic
docker.withRegistry(REGISTRY_URL, REGISTRY_CREDENTIALS_ID) {
stage("checkout") {
gerrit.gerritPatchsetCheckout(IMAGE_GIT_URL, "", IMAGE_BRANCH, IMAGE_CREDENTIALS_ID)
}
stage("build") {
common.infoMsg("Building aptly")
aptly = dockerLib.buildDockerImage("mirantis/aptly", "", "docker/aptly.Dockerfile", imageTagsList[0])
if(!aptly){
throw new Exception("Docker aptly build image failed")
}
common.infoMsg("Building aptly-api ")
aptlyApi = dockerLib.buildDockerImage("mirantis/aptly-api", "", "docker/aptly-api.Dockerfile", imageTagsList[0])
if(!aptlyApi){
throw new Exception("Docker aptly-api build image failed")
}
common.infoMsg("Building aptly-publisher")
aptlyPublisher = dockerLib.buildDockerImage("mirantis/aptly-publisher", "", "docker/aptly-publisher.Dockerfile", imageTagsList[0])
if(!aptlyPublisher){
throw new Exception("Docker aptly-publisher build image failed")
}
common.infoMsg("Building aptly-public")
aptlyPublic = dockerLib.buildDockerImage("mirantis/aptly-public", "", "docker/aptly-public.Dockerfile", imageTagsList[0])
if(!aptlyPublic){
throw new Exception("Docker aptly-public build image failed")
}
}
stage("upload to docker hub"){
common.infoMsg("Uploading aptly image with tags ${imageTagsList}")
for(int i=0;i<imageTagsList.size();i++){
aptly.push(imageTagsList[i])
}
common.infoMsg("Uploading aptly-api image with tags ${imageTagsList}")
for(int i=0;i<imageTagsList.size();i++){
aptlyApi.push(imageTagsList[i])
}
common.infoMsg("Uploading aptly-publisher image with tags ${imageTagsList}")
for(int i=0;i<imageTagsList.size();i++){
aptlyPublisher.push(imageTagsList[i])
}
common.infoMsg("Uploading aptly-public image with tags ${imageTagsList}")
for(int i=0;i<imageTagsList.size();i++){
aptlyPublic.push(imageTagsList[i])
}
}
}
} catch (Throwable e) {
// If there was an error or exception thrown, the build failed
currentBuild.result = "FAILURE"
throw e
} finally {
common.sendNotification(currentBuild.result,"",["slack"])
}
}