chnyda | a8d1634 | 2017-06-20 17:18:25 +0200 | [diff] [blame] | 1 | def common = new com.mirantis.mk.Common() |
| 2 | def git = new com.mirantis.mk.Git() |
| 3 | def aptly = new com.mirantis.mk.Aptly() |
chnyda | 98e6069 | 2017-06-28 16:43:00 +0200 | [diff] [blame] | 4 | def dockerLib = new com.mirantis.mk.Docker() |
chnyda | a8d1634 | 2017-06-20 17:18:25 +0200 | [diff] [blame] | 5 | |
| 6 | def timestamp = common.getDatetime() |
| 7 | |
| 8 | node('docker') { |
chnyda | 98e6069 | 2017-06-28 16:43:00 +0200 | [diff] [blame] | 9 | try { |
| 10 | def img = dockerLib.getImage("tcpcloud/debian-build-ubuntu-${DIST}") |
chnyda | a8d1634 | 2017-06-20 17:18:25 +0200 | [diff] [blame] | 11 | |
chnyda | 98e6069 | 2017-06-28 16:43:00 +0200 | [diff] [blame] | 12 | img.inside ("-u root:root") { |
chnyda | a8d1634 | 2017-06-20 17:18:25 +0200 | [diff] [blame] | 13 | sh("rm -rf * || true") |
| 14 | } |
| 15 | |
| 16 | stage("checkout") { |
| 17 | git.checkoutGitRepository( |
| 18 | "jmx-exporter-${timestamp}", |
| 19 | "${SOURCE_URL}", |
| 20 | SOURCE_BRANCH, |
| 21 | SOURCE_CREDENTIALS, |
| 22 | true, |
| 23 | 30, |
| 24 | 1 |
| 25 | ) |
| 26 | } |
| 27 | |
chnyda | 98e6069 | 2017-06-28 16:43:00 +0200 | [diff] [blame] | 28 | img.inside ("-u root:root") { |
| 29 | stage("Build") { |
| 30 | sh("sed -i \"s/TIMESTAMP/${timestamp}/g\" \$(find -name pom.xml)") |
| 31 | sh("sudo apt-get update && sudo apt-get install -y openjdk-8-jdk maven") |
| 32 | sh("cd jmx-exporter-${timestamp} && mvn package") |
| 33 | } |
| 34 | } |
chnyda | a8d1634 | 2017-06-20 17:18:25 +0200 | [diff] [blame] | 35 | |
chnyda | 98e6069 | 2017-06-28 16:43:00 +0200 | [diff] [blame] | 36 | if (UPLOAD_APTLY.toBoolean()) { |
| 37 | stage("upload package") { |
| 38 | def buildSteps = [:] |
| 39 | def debFiles = sh script: "find -name *.deb", returnStdout: true |
| 40 | def debFilesArray = debFiles.trim().tokenize() |
| 41 | def workspace = common.getWorkspace() |
| 42 | for (int i = 0; i < debFilesArray.size(); i++) { |
| 43 | def debFile = debFilesArray[i]; |
| 44 | buildSteps[debFiles[i]] = aptly.uploadPackageStep( |
| 45 | "${workspace}/"+debFile, |
| 46 | APTLY_URL, |
| 47 | APTLY_REPO, |
| 48 | true |
| 49 | ) |
chnyda | a8d1634 | 2017-06-20 17:18:25 +0200 | [diff] [blame] | 50 | } |
chnyda | 98e6069 | 2017-06-28 16:43:00 +0200 | [diff] [blame] | 51 | parallel buildSteps |
chnyda | a8d1634 | 2017-06-20 17:18:25 +0200 | [diff] [blame] | 52 | } |
| 53 | |
chnyda | 98e6069 | 2017-06-28 16:43:00 +0200 | [diff] [blame] | 54 | stage("publish") { |
| 55 | aptly.snapshotRepo(APTLY_URL, APTLY_REPO, timestamp) |
| 56 | aptly.publish(APTLY_URL) |
chnyda | a8d1634 | 2017-06-20 17:18:25 +0200 | [diff] [blame] | 57 | } |
chnyda | 98e6069 | 2017-06-28 16:43:00 +0200 | [diff] [blame] | 58 | } |
chnyda | a8d1634 | 2017-06-20 17:18:25 +0200 | [diff] [blame] | 59 | |
chnyda | 98e6069 | 2017-06-28 16:43:00 +0200 | [diff] [blame] | 60 | img.inside ("-u root:root") { |
| 61 | sh("rm -rf * || true") |
chnyda | a8d1634 | 2017-06-20 17:18:25 +0200 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | } catch (Throwable e) { |
| 65 | // If there was an exception thrown, the build failed |
| 66 | currentBuild.result = "FAILURE" |
| 67 | throw e |
| 68 | } finally { |
| 69 | common.sendNotification(currentBuild.result,"",["slack"]) |
chnyda | a8d1634 | 2017-06-20 17:18:25 +0200 | [diff] [blame] | 70 | } |
| 71 | } |