blob: 3a9bc0349dc267633205dd16417ea136642d8cb2 [file] [log] [blame]
Simon Pasquierf1280742017-08-25 14:25:48 +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 = "1.0~${timestamp}"
Jakub Josefa63f9862018-01-11 17:58:38 +01008timeout(time: 12, unit: 'HOURS') {
9 node('docker') {
10 try{
Simon Pasquierf1280742017-08-25 14:25:48 +020011
Jakub Josefa63f9862018-01-11 17:58:38 +010012 stage("cleanup") {
13 sh("rm -rf * || true")
14 }
Simon Pasquierf1280742017-08-25 14:25:48 +020015
Jakub Josefa63f9862018-01-11 17:58:38 +010016 def workingDir = "src/github.com/influxdata"
17 stage("checkout") {
18 git.checkoutGitRepository(
19 "${workingDir}/influxdb-relay",
20 "${SOURCE_URL}",
21 SOURCE_BRANCH,
22 SOURCE_CREDENTIALS,
23 true,
24 30,
25 1
Simon Pasquierf1280742017-08-25 14:25:48 +020026 )
27 }
Simon Pasquierf1280742017-08-25 14:25:48 +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}/influxdb-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.9.linux-amd64.tar.gz &&
52 tar xf go1.9.linux-amd64.tar.gz &&
53 export GOROOT=\$PWD/go &&
54 export PATH=\$PATH:\$GOROOT/bin &&
55 export GOPATH=\$PWD &&
56 cd src/github.com/influxdata/influxdb-relay &&
57 ./build.py --package --version=\"${version}\" --platform=linux --arch=amd64""")
58 }
59 archiveArtifacts artifacts: "${workingDir}/influxdb-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}/influxdb-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
Simon Pasquierf1280742017-08-25 14:25:48 +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 }
Simon Pasquierf1280742017-08-25 14:25:48 +020084 }
85 }
Jakub Josefa63f9862018-01-11 17:58:38 +010086
87 } catch (Exception e) {
88 currentBuild.result = 'FAILURE'
89 println "Cleaning up docker images"
90 sh("docker images | grep -E '[-:\\ ]+${timestamp}[\\.\\ /\$]+' | awk '{print \$3}' | xargs docker rmi -f || true")
91 throw e
Simon Pasquierf1280742017-08-25 14:25:48 +020092 }
93
Jakub Josefa63f9862018-01-11 17:58:38 +010094 } catch (Throwable e) {
95 // If there was an exception thrown, the build failed
96 currentBuild.result = "FAILURE"
97 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
98 throw e
99 } finally {
100 common.sendNotification(currentBuild.result,"",["slack"])
101
102 if (currentBuild.result != 'FAILURE') {
103 sh("rm -rf *")
104 }
Simon Pasquierf1280742017-08-25 14:25:48 +0200105 }
Simon Pasquierf1280742017-08-25 14:25:48 +0200106 }
107}