chnyda | 1e21f22 | 2017-04-20 19:18:16 +0200 | [diff] [blame] | 1 | def common = new com.mirantis.mk.Common() |
| 2 | def git = new com.mirantis.mk.Git() |
| 3 | def artifactory = new com.mirantis.mk.Artifactory() |
| 4 | def aptly = new com.mirantis.mk.Aptly() |
| 5 | |
| 6 | def timestamp = common.getDatetime() |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 7 | timeout(time: 12, unit: 'HOURS') { |
| 8 | node('docker') { |
| 9 | try{ |
chnyda | 1e21f22 | 2017-04-20 19:18:16 +0200 | [diff] [blame] | 10 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 11 | stage("cleanup") { |
| 12 | sh("rm -rf * || true") |
| 13 | } |
chnyda | 1e21f22 | 2017-04-20 19:18:16 +0200 | [diff] [blame] | 14 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 15 | 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 |
chnyda | 1e21f22 | 2017-04-20 19:18:16 +0200 | [diff] [blame] | 25 | ) |
| 26 | } |
chnyda | 1e21f22 | 2017-04-20 19:18:16 +0200 | [diff] [blame] | 27 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 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", |
| 44 | "." |
| 45 | ].join(' ') |
| 46 | ) |
| 47 | } |
| 48 | stage("build package") { |
| 49 | img.inside{ |
| 50 | sh("""wget https://storage.googleapis.com/golang/go1.9.2.linux-amd64.tar.gz && |
| 51 | tar xf go1.9.2.linux-amd64.tar.gz && |
| 52 | 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 |
chnyda | e4ff8e5 | 2017-04-22 09:40:51 +0200 | [diff] [blame] | 78 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 79 | stage("publish") { |
| 80 | aptly.snapshotRepo(APTLY_URL, APTLY_REPO, timestamp) |
| 81 | aptly.publish(APTLY_URL) |
| 82 | } |
chnyda | e9d813e | 2017-08-22 10:55:18 +0200 | [diff] [blame] | 83 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 84 | stage("rebuild docker images") { |
| 85 | build job: "docker-build-images-prometheus", parameters: [] |
| 86 | } |
chnyda | e9d813e | 2017-08-22 10:55:18 +0200 | [diff] [blame] | 87 | } |
chnyda | 1e21f22 | 2017-04-20 19:18:16 +0200 | [diff] [blame] | 88 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 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 |
chnyda | 1e21f22 | 2017-04-20 19:18:16 +0200 | [diff] [blame] | 95 | } |
| 96 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 97 | } catch (Throwable e) { |
| 98 | // If there was an exception thrown, the build failed |
| 99 | currentBuild.result = "FAILURE" |
| 100 | currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message |
| 101 | throw e |
| 102 | } finally { |
| 103 | common.sendNotification(currentBuild.result,"",["slack"]) |
| 104 | |
| 105 | if (currentBuild.result != 'FAILURE') { |
| 106 | sh("rm -rf *") |
| 107 | } |
chnyda | 1e21f22 | 2017-04-20 19:18:16 +0200 | [diff] [blame] | 108 | } |
chnyda | 1e21f22 | 2017-04-20 19:18:16 +0200 | [diff] [blame] | 109 | } |
| 110 | } |