blob: 043298d19fb602eb3d21b3036f33377f297ac488 [file] [log] [blame]
Krzysztof Szukiełojć8d6c7ae2017-09-11 14:00:40 +02001def common = new com.mirantis.mk.Common()
2def git = new com.mirantis.mk.Git()
3def artifactory = new com.mirantis.mk.Artifactory()
4def aptly = new com.mirantis.mk.Aptly()
5
6def timestamp = common.getDatetime()
7def version = "0.1~${timestamp}"
8
9node('docker') {
10 try{
11
12 stage("cleanup") {
13 sh("rm -rf * || true")
14 }
15
16 def workingDir = "src/gerrit.mcp.mirantis.net/debian"
17 stage("checkout") {
18 git.checkoutGitRepository(
19 "${workingDir}/prometheus-relay",
20 "${SOURCE_URL}",
21 SOURCE_BRANCH,
22 SOURCE_CREDENTIALS,
23 true,
24 30,
25 1
26 )
27 }
28
29 try {
30
31 def jenkinsUID = sh (
32 script: 'id -u',
33 returnStdout: true
34 ).trim()
35 def imgName = "${OS}-${DIST}-${ARCH}"
36 def img
37
Krzysztof Szukiełojćee8dc932017-09-13 20:01:00 +020038 stage("build image") {
39 img = docker.build(
40 "${imgName}:${timestamp}",
41 [
42 "--build-arg uid=${jenkinsUID}",
43 "--build-arg timestamp=${timestamp}",
44 "-f ${workingDir}/prometheus-relay/docker/${OS}-${DIST}-${ARCH}.Dockerfile",
45 "."
46 ].join(' ')
47 )
48 }
Krzysztof Szukiełojć8d6c7ae2017-09-11 14:00:40 +020049 stage("build package") {
50 img.inside{
51 sh("""wget https://storage.googleapis.com/golang/go1.8.1.linux-amd64.tar.gz &&
52 tar xf go1.8.1.linux-amd64.tar.gz &&
53 export GOROOT=\$PWD/go &&
Krzysztof Szukiełojć8d6c7ae2017-09-11 14:00:40 +020054 export GOPATH=\$PWD &&
Krzysztof Szukiełojć81746162017-09-14 09:33:35 +020055 export PATH=\$PATH:\$GOPATH/bin:\$GOROOT/bin &&
Krzysztof Szukiełojć8d6c7ae2017-09-11 14:00:40 +020056 cd src/gerrit.mcp.mirantis.net/debian/prometheus-relay &&
57 make""")
58 }
59 archiveArtifacts artifacts: "${workingDir}/prometheus-relay/build/*.deb"
60 }
61 if (UPLOAD_APTLY.toBoolean()) {
62 lock("aptly-api") {
63 stage("upload") {
64 def buildSteps = [:]
65 def debFiles = sh script: "ls ${workingDir}/prometheus-relay/build/*.deb", returnStdout: true
66 def debFilesArray = debFiles.trim().tokenize()
67 def workspace = common.getWorkspace()
68 for (int i = 0; i < debFilesArray.size(); i++) {
69
70 def debFile = debFilesArray[i];
71 buildSteps[debFiles[i]] = aptly.uploadPackageStep(
72 "${workspace}/"+debFile,
73 APTLY_URL,
74 APTLY_REPO,
75 true
76 )
77 }
78 parallel buildSteps
79 }
80 stage("publish") {
81 aptly.snapshotRepo(APTLY_URL, APTLY_REPO, timestamp)
82 aptly.publish(APTLY_URL)
83 }
84
Krzysztof Szukiełojć1035ef42017-09-14 10:11:18 +020085 stage("rebuild docker images")
86 build job: "docker-build-images-prometheus", parameters: []
87 }
Krzysztof Szukiełojć8d6c7ae2017-09-11 14:00:40 +020088 }
89 }
90
91 } catch (Exception e) {
92 currentBuild.result = 'FAILURE'
93 throw e
94 }
95
96 } catch (Throwable e) {
97 // If there was an exception thrown, the build failed
98 currentBuild.result = "FAILURE"
99 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
100 throw e
101 } finally {
102 common.sendNotification(currentBuild.result,"",["slack"])
103
104 if (currentBuild.result != 'FAILURE') {
105 sh("rm -rf *")
106 }
107 }
108}