blob: efcddaaead617a34c36de1c658a3e9b82f4ad329 [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()
chnyda1e21f222017-04-20 19:18:16 +02007
8node('docker') {
9 try{
10
11 stage("cleanup") {
12 sh("rm -rf * || true")
13 }
14
15 def workingDir = "src/github.com/influxdata"
16 stage("checkout") {
17 git.checkoutGitRepository(
18 "${workingDir}/telegraf",
chnyda35306a12017-04-21 14:15:37 +020019 "${SOURCE_URL}",
chnyda1e21f222017-04-20 19:18:16 +020020 SOURCE_BRANCH,
21 SOURCE_CREDENTIALS,
22 true,
23 30,
24 1
25 )
26 }
27
28 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",
chnydaf27c79a2017-04-21 14:27:32 +020044 "."
chnyda1e21f222017-04-20 19:18:16 +020045 ].join(' ')
46 )
47 }
48 stage("build package") {
49 img.inside{
Ildar Svetlovd5f05662017-12-19 10:11:17 +040050 sh("""wget https://storage.googleapis.com/golang/go1.9.2.linux-amd64.tar.gz &&
51 tar xf go1.9.2.linux-amd64.tar.gz &&
chnydaf8a0e0f2017-04-21 15:20:54 +020052 export GOROOT=\$PWD/go &&
53 export PATH=\$PATH:\$GOROOT/bin &&
54 export GOPATH=\$PWD &&
chnyda5b1a96c2017-04-21 14:22:53 +020055 cd src/github.com/influxdata/telegraf &&
Ildar Svetlov4770a182017-12-19 18:27:15 +040056 scripts/build.py --package --platform=linux --arch=amd64""")
chnyda1e21f222017-04-20 19:18:16 +020057 }
chnyda311251e2017-04-22 10:27:50 +020058 archiveArtifacts artifacts: "${workingDir}/telegraf/build/*.deb"
chnyda1e21f222017-04-20 19:18:16 +020059 }
chnydae4ff8e52017-04-22 09:40:51 +020060 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++) {
chnyda1e21f222017-04-20 19:18:16 +020068
chnydae4ff8e52017-04-22 09:40:51 +020069 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
chnyda1e21f222017-04-20 19:18:16 +020078 }
chnydae4ff8e52017-04-22 09:40:51 +020079 stage("publish") {
80 aptly.snapshotRepo(APTLY_URL, APTLY_REPO, timestamp)
81 aptly.publish(APTLY_URL)
82 }
chnydae9d813e2017-08-22 10:55:18 +020083
84 stage("rebuild docker images") {
85 build job: "docker-build-images-prometheus", parameters: []
86 }
chnyda1e21f222017-04-20 19:18:16 +020087 }
88 }
89
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
95 }
96
97 } catch (Throwable e) {
98 // If there was an exception thrown, the build failed
99 currentBuild.result = "FAILURE"
Jakub Josefd2efd7d2017-08-22 17:49:57 +0200100 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
chnyda1e21f222017-04-20 19:18:16 +0200101 throw e
102 } finally {
103 common.sendNotification(currentBuild.result,"",["slack"])
104
105 if (currentBuild.result != 'FAILURE') {
106 sh("rm -rf *")
107 }
108 }
109}