blob: dde098ef10f04c239ea1f6af3b56c61dc56fd598 [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()
chnyda311251e2017-04-22 10:27:50 +02007def version = "1.3~${timestamp}"
chnyda1e21f222017-04-20 19:18:16 +02008
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 }
chnyda311251e2017-04-22 10:27:50 +020059 archiveArtifacts artifacts: "${workingDir}/telegraf/build/*.deb"
chnyda1e21f222017-04-20 19:18:16 +020060 }
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 }
chnydae9d813e2017-08-22 10:55:18 +020084
85 stage("rebuild docker images") {
86 build job: "docker-build-images-prometheus", parameters: []
87 }
chnyda1e21f222017-04-20 19:18:16 +020088 }
89 }
90
91 } catch (Exception e) {
92 currentBuild.result = 'FAILURE'
93 println "Cleaning up docker images"
94 sh("docker images | grep -E '[-:\\ ]+${timestamp}[\\.\\ /\$]+' | awk '{print \$3}' | xargs docker rmi -f || true")
95 throw e
96 }
97
98 } catch (Throwable e) {
99 // If there was an exception thrown, the build failed
100 currentBuild.result = "FAILURE"
Jakub Josefd2efd7d2017-08-22 17:49:57 +0200101 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
chnyda1e21f222017-04-20 19:18:16 +0200102 throw e
103 } finally {
104 common.sendNotification(currentBuild.result,"",["slack"])
105
106 if (currentBuild.result != 'FAILURE') {
107 sh("rm -rf *")
108 }
109 }
110}