blob: 566c097ecbea8c8cce29bd163866da7935b37cef [file] [log] [blame]
chnyda1e21f222017-04-20 19:18:16 +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()
Jakub Josefa63f9862018-01-11 17:58:38 +01007timeout(time: 12, unit: 'HOURS') {
8 node('docker') {
9 try{
chnyda1e21f222017-04-20 19:18:16 +020010
Jakub Josefa63f9862018-01-11 17:58:38 +010011 stage("cleanup") {
12 sh("rm -rf * || true")
13 }
chnyda1e21f222017-04-20 19:18:16 +020014
Jakub Josefa63f9862018-01-11 17:58:38 +010015 def workingDir = "src/github.com/influxdata"
16 stage("checkout") {
17 git.checkoutGitRepository(
18 "${workingDir}/telegraf",
19 "${SOURCE_URL}",
20 SOURCE_BRANCH,
21 SOURCE_CREDENTIALS,
22 true,
23 30,
24 1
chnyda1e21f222017-04-20 19:18:16 +020025 )
26 }
chnyda1e21f222017-04-20 19:18:16 +020027
Jakub Josefa63f9862018-01-11 17:58:38 +010028 try {
29
30 def jenkinsUID = sh (
31 script: 'id -u',
32 returnStdout: true
33 ).trim()
34 def imgName = "${OS}-${DIST}-${ARCH}"
35 def img
36
37 stage("build image") {
38 img = docker.build(
39 "${imgName}:${timestamp}",
40 [
41 "--build-arg uid=${jenkinsUID}",
42 "--build-arg timestamp=${timestamp}",
43 "-f ${workingDir}/telegraf/docker/${OS}-${DIST}-${ARCH}.Dockerfile",
44 "."
45 ].join(' ')
46 )
47 }
48 stage("build package") {
49 img.inside{
50 sh("""wget https://storage.googleapis.com/golang/go1.9.2.linux-amd64.tar.gz &&
51 tar xf go1.9.2.linux-amd64.tar.gz &&
52 export GOROOT=\$PWD/go &&
53 export PATH=\$PATH:\$GOROOT/bin &&
54 export GOPATH=\$PWD &&
55 cd src/github.com/influxdata/telegraf &&
56 scripts/build.py --package --platform=linux --arch=amd64""")
57 }
58 archiveArtifacts artifacts: "${workingDir}/telegraf/build/*.deb"
59 }
60 if (UPLOAD_APTLY.toBoolean()) {
61 lock("aptly-api") {
62 stage("upload") {
63 def buildSteps = [:]
64 def debFiles = sh script: "ls ${workingDir}/telegraf/build/*.deb", returnStdout: true
65 def debFilesArray = debFiles.trim().tokenize()
66 def workspace = common.getWorkspace()
67 for (int i = 0; i < debFilesArray.size(); i++) {
68
69 def debFile = debFilesArray[i];
70 buildSteps[debFiles[i]] = aptly.uploadPackageStep(
71 "${workspace}/"+debFile,
72 APTLY_URL,
73 APTLY_REPO,
74 true
75 )
76 }
77 parallel buildSteps
chnydae4ff8e52017-04-22 09:40:51 +020078 }
Jakub Josefa63f9862018-01-11 17:58:38 +010079 stage("publish") {
80 aptly.snapshotRepo(APTLY_URL, APTLY_REPO, timestamp)
81 aptly.publish(APTLY_URL)
82 }
chnydae9d813e2017-08-22 10:55:18 +020083
Jakub Josefa63f9862018-01-11 17:58:38 +010084 stage("rebuild docker images") {
85 build job: "docker-build-images-prometheus", parameters: []
86 }
chnydae9d813e2017-08-22 10:55:18 +020087 }
chnyda1e21f222017-04-20 19:18:16 +020088 }
Jakub Josefa63f9862018-01-11 17:58:38 +010089
90 } catch (Exception e) {
91 currentBuild.result = 'FAILURE'
92 println "Cleaning up docker images"
93 sh("docker images | grep -E '[-:\\ ]+${timestamp}[\\.\\ /\$]+' | awk '{print \$3}' | xargs docker rmi -f || true")
94 throw e
chnyda1e21f222017-04-20 19:18:16 +020095 }
96
Jakub Josefa63f9862018-01-11 17:58:38 +010097 } catch (Throwable e) {
98 // If there was an exception thrown, the build failed
99 currentBuild.result = "FAILURE"
100 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
101 throw e
102 } finally {
103 common.sendNotification(currentBuild.result,"",["slack"])
104
105 if (currentBuild.result != 'FAILURE') {
106 sh("rm -rf *")
107 }
chnyda1e21f222017-04-20 19:18:16 +0200108 }
chnyda1e21f222017-04-20 19:18:16 +0200109 }
110}