blob: 31309570fe61d2ef1fa0a785b15a327c2545ab5d [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 }
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()
chnydaf8a0e0f2017-04-21 15:20:54 +020066 def workspace = common.getWorkspace()
chnyda1e21f222017-04-20 19:18:16 +020067 for (int i = 0; i < debFilesArray.size(); i++) {
68
chnydaf8a0e0f2017-04-21 15:20:54 +020069 def debFile = debFilesArray[i];
chnyda1e21f222017-04-20 19:18:16 +020070 buildSteps[debFiles[i]] = aptly.uploadPackageStep(
chnydadb9f1382017-04-21 15:44:47 +020071 "${workspace}/"+debFile,
chnyda1e21f222017-04-20 19:18:16 +020072 APTLY_URL,
73 APTLY_REPO,
74 true
75 )
76 }
77 parallel buildSteps
78 }
79 stage("publish") {
80 aptly.snapshotRepo(APTLY_URL, APTLY_REPO, timestamp)
81 aptly.publish(APTLY_URL)
82 }
83 }
84
85 } catch (Exception e) {
86 currentBuild.result = 'FAILURE'
87 println "Cleaning up docker images"
88 sh("docker images | grep -E '[-:\\ ]+${timestamp}[\\.\\ /\$]+' | awk '{print \$3}' | xargs docker rmi -f || true")
89 throw e
90 }
91
92 } catch (Throwable e) {
93 // If there was an exception thrown, the build failed
94 currentBuild.result = "FAILURE"
95 throw e
96 } finally {
97 common.sendNotification(currentBuild.result,"",["slack"])
98
99 if (currentBuild.result != 'FAILURE') {
100 sh("rm -rf *")
101 }
102 }
103}