blob: 45e5b100366f28d97415dbac542210eac9c49303 [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}"
Jakub Josefa63f9862018-01-11 17:58:38 +01008timeout(time: 12, unit: 'HOURS') {
9 node('docker') {
10 try{
Krzysztof Szukiełojć8d6c7ae2017-09-11 14:00:40 +020011
Jakub Josefa63f9862018-01-11 17:58:38 +010012 stage("cleanup") {
13 sh("rm -rf * || true")
14 }
Krzysztof Szukiełojć8d6c7ae2017-09-11 14:00:40 +020015
Jakub Josefa63f9862018-01-11 17:58:38 +010016 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
Krzysztof Szukiełojćee8dc932017-09-13 20:01:00 +020026 )
27 }
Krzysztof Szukiełojć8d6c7ae2017-09-11 14:00:40 +020028
Jakub Josefa63f9862018-01-11 17:58:38 +010029 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
38 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 }
49 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 &&
54 export GOPATH=\$PWD &&
55 export PATH=\$PATH:\$GOPATH/bin:\$GOROOT/bin &&
56 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
Krzysztof Szukiełojć8d6c7ae2017-09-11 14:00:40 +020079 }
Jakub Josefa63f9862018-01-11 17:58:38 +010080 stage("publish") {
81 aptly.snapshotRepo(APTLY_URL, APTLY_REPO, timestamp)
82 aptly.publish(APTLY_URL)
83 }
Krzysztof Szukiełojć8d6c7ae2017-09-11 14:00:40 +020084
Jakub Josefa63f9862018-01-11 17:58:38 +010085 stage("rebuild docker images") {
86 build job: "docker-build-images-prometheus", parameters: []
87 }
Krzysztof Szukiełojć1035ef42017-09-14 10:11:18 +020088 }
Krzysztof Szukiełojć8d6c7ae2017-09-11 14:00:40 +020089 }
Jakub Josefa63f9862018-01-11 17:58:38 +010090
91 } catch (Exception e) {
92 currentBuild.result = 'FAILURE'
93 throw e
Krzysztof Szukiełojć8d6c7ae2017-09-11 14:00:40 +020094 }
95
Jakub Josefa63f9862018-01-11 17:58:38 +010096 } 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 }
Krzysztof Szukiełojć8d6c7ae2017-09-11 14:00:40 +0200107 }
Krzysztof Szukiełojć8d6c7ae2017-09-11 14:00:40 +0200108 }
109}