blob: 293783b6f579a051b507eb7210c6924c005a8d95 [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()
7def version = timestamp
8
9node('docker') {
10 try{
11
12 stage("cleanup") {
13 sh("rm -rf * || true")
14 }
15
16 def workingDir = "src/github.com/influxdata"
17 stage("checkout") {
18 git.checkoutGitRepository(
19 "${workingDir}/telegraf",
chnyda35306a12017-04-21 14:15:37 +020020 "${SOURCE_URL}",
chnyda1e21f222017-04-20 19:18:16 +020021 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 image") {
39 img = docker.build(
40 "${imgName}:${timestamp}",
41 [
42 "--build-arg uid=${jenkinsUID}",
43 "--build-arg timestamp=${timestamp}",
44 "-f ${workingDir}/telegraf/docker/${OS}-${DIST}-${ARCH}.Dockerfile",
chnydaf27c79a2017-04-21 14:27:32 +020045 "."
chnyda1e21f222017-04-20 19:18:16 +020046 ].join(' ')
47 )
48 }
49 stage("build package") {
50 img.inside{
chnyda5b1a96c2017-04-21 14:22:53 +020051 sh("""wget https://storage.googleapis.com/golang/go1.8.1.linux-amd64.tar.gz &&
52 tar xf go1.8.1.linux-amd64.tar.gz &&
chnydaf8a0e0f2017-04-21 15:20:54 +020053 export GOROOT=\$PWD/go &&
54 export PATH=\$PATH:\$GOROOT/bin &&
55 export GOPATH=\$PWD &&
chnyda5b1a96c2017-04-21 14:22:53 +020056 cd src/github.com/influxdata/telegraf &&
57 scripts/build.py --package --version=\"${version}\" --platform=linux --arch=amd64""")
chnyda1e21f222017-04-20 19:18:16 +020058 }
59 archiveArtifacts artifacts: "${workingDir}/*.deb"
60 }
chnydae4ff8e52017-04-22 09:40:51 +020061 if (UPLOAD_APTLY.toBoolean()) {
62 lock("aptly-api") {
63 stage("upload") {
64 def buildSteps = [:]
65 def debFiles = sh script: "ls ${workingDir}/telegraf/build/*.deb", returnStdout: true
66 def debFilesArray = debFiles.trim().tokenize()
67 def workspace = common.getWorkspace()
68 for (int i = 0; i < debFilesArray.size(); i++) {
chnyda1e21f222017-04-20 19:18:16 +020069
chnydae4ff8e52017-04-22 09:40:51 +020070 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
chnyda1e21f222017-04-20 19:18:16 +020079 }
chnydae4ff8e52017-04-22 09:40:51 +020080 stage("publish") {
81 aptly.snapshotRepo(APTLY_URL, APTLY_REPO, timestamp)
82 aptly.publish(APTLY_URL)
83 }
chnyda1e21f222017-04-20 19:18:16 +020084 }
85 }
86
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
92 }
93
94 } catch (Throwable e) {
95 // If there was an exception thrown, the build failed
96 currentBuild.result = "FAILURE"
97 throw e
98 } finally {
99 common.sendNotification(currentBuild.result,"",["slack"])
100
101 if (currentBuild.result != 'FAILURE') {
102 sh("rm -rf *")
103 }
104 }
105}