blob: b48c4fa7aec6ba676a36c88ba84297e9992c89e7 [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{
Ildar Svetlov222ba7d2018-03-16 16:39:13 +040050 sh("""wget https://storage.googleapis.com/golang/go1.9.4.linux-amd64.tar.gz &&
51 tar xf go1.9.4.linux-amd64.tar.gz &&
Jakub Josefa63f9862018-01-11 17:58:38 +010052 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)
Jakub Josef01719f72018-03-26 12:28:49 +020081 retry(2){
82 aptly.publish(APTLY_URL)
83 }
Jakub Josefa63f9862018-01-11 17:58:38 +010084 }
chnydae9d813e2017-08-22 10:55:18 +020085
Jakub Josefa63f9862018-01-11 17:58:38 +010086 stage("rebuild docker images") {
87 build job: "docker-build-images-prometheus", parameters: []
88 }
chnydae9d813e2017-08-22 10:55:18 +020089 }
chnyda1e21f222017-04-20 19:18:16 +020090 }
Jakub Josefa63f9862018-01-11 17:58:38 +010091
92 } catch (Exception e) {
93 currentBuild.result = 'FAILURE'
94 println "Cleaning up docker images"
95 sh("docker images | grep -E '[-:\\ ]+${timestamp}[\\.\\ /\$]+' | awk '{print \$3}' | xargs docker rmi -f || true")
96 throw e
chnyda1e21f222017-04-20 19:18:16 +020097 }
98
Jakub Josefa63f9862018-01-11 17:58:38 +010099 } catch (Throwable e) {
100 // If there was an exception thrown, the build failed
101 currentBuild.result = "FAILURE"
102 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
103 throw e
104 } finally {
105 common.sendNotification(currentBuild.result,"",["slack"])
106
107 if (currentBuild.result != 'FAILURE') {
108 sh("rm -rf *")
109 }
chnyda1e21f222017-04-20 19:18:16 +0200110 }
chnyda1e21f222017-04-20 19:18:16 +0200111 }
112}