blob: 9f79e35db638d4c5abc9d389f6bf873fb4e95ae0 [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
38 stage("build package") {
39 img.inside{
40 sh("""wget https://storage.googleapis.com/golang/go1.8.1.linux-amd64.tar.gz &&
41 tar xf go1.8.1.linux-amd64.tar.gz &&
42 export GOROOT=\$PWD/go &&
43 export PATH=\$PATH:\$GOROOT/bin &&
44 export GOPATH=\$PWD &&
45 cd src/gerrit.mcp.mirantis.net/debian/prometheus-relay &&
46 make""")
47 }
48 archiveArtifacts artifacts: "${workingDir}/prometheus-relay/build/*.deb"
49 }
50 if (UPLOAD_APTLY.toBoolean()) {
51 lock("aptly-api") {
52 stage("upload") {
53 def buildSteps = [:]
54 def debFiles = sh script: "ls ${workingDir}/prometheus-relay/build/*.deb", returnStdout: true
55 def debFilesArray = debFiles.trim().tokenize()
56 def workspace = common.getWorkspace()
57 for (int i = 0; i < debFilesArray.size(); i++) {
58
59 def debFile = debFilesArray[i];
60 buildSteps[debFiles[i]] = aptly.uploadPackageStep(
61 "${workspace}/"+debFile,
62 APTLY_URL,
63 APTLY_REPO,
64 true
65 )
66 }
67 parallel buildSteps
68 }
69 stage("publish") {
70 aptly.snapshotRepo(APTLY_URL, APTLY_REPO, timestamp)
71 aptly.publish(APTLY_URL)
72 }
73
74 }
75 }
76
77 } catch (Exception e) {
78 currentBuild.result = 'FAILURE'
79 throw e
80 }
81
82 } catch (Throwable e) {
83 // If there was an exception thrown, the build failed
84 currentBuild.result = "FAILURE"
85 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
86 throw e
87 } finally {
88 common.sendNotification(currentBuild.result,"",["slack"])
89
90 if (currentBuild.result != 'FAILURE') {
91 sh("rm -rf *")
92 }
93 }
94}