blob: 2e4d71a1f30a5086f81b4d3918ac21e030ba51bd [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",
45 "docker"
46 ].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 &&
53 export GOROOT=$PWD/go &&
54 export PATH=$PATH:$GOROOT/bin &&
55 export GOPATH=$PWD &&
56 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()
66 for (int i = 0; i < debFilesArray.size(); i++) {
67
68 def debFile = debFiles[i];
69 buildSteps[debFiles[i]] = aptly.uploadPackageStep(
70 "${workingDir}/telegraf/build/"+debFile,
71 APTLY_URL,
72 APTLY_REPO,
73 true
74 )
75 }
76 parallel buildSteps
77 }
78 stage("publish") {
79 aptly.snapshotRepo(APTLY_URL, APTLY_REPO, timestamp)
80 aptly.publish(APTLY_URL)
81 }
82 }
83
84 } catch (Exception e) {
85 currentBuild.result = 'FAILURE'
86 println "Cleaning up docker images"
87 sh("docker images | grep -E '[-:\\ ]+${timestamp}[\\.\\ /\$]+' | awk '{print \$3}' | xargs docker rmi -f || true")
88 throw e
89 }
90
91 } catch (Throwable e) {
92 // If there was an exception thrown, the build failed
93 currentBuild.result = "FAILURE"
94 throw e
95 } finally {
96 common.sendNotification(currentBuild.result,"",["slack"])
97
98 if (currentBuild.result != 'FAILURE') {
99 sh("rm -rf *")
100 }
101 }
102}