chnyda | 8fd09df | 2017-05-18 15:17:11 +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 | 0bae467 | 2017-06-20 13:39:35 +0200 | [diff] [blame] | 4 | def dockerLib = new com.mirantis.mk.Docker() |
chnyda | 8fd09df | 2017-05-18 15:17:11 +0200 | [diff] [blame] | 5 | |
| 6 | def timestamp = common.getDatetime() |
| 7 | def version = "0.1~${timestamp}" |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 8 | timeout(time: 12, unit: 'HOURS') { |
| 9 | node('docker') { |
| 10 | try{ |
chnyda | 8fd09df | 2017-05-18 15:17:11 +0200 | [diff] [blame] | 11 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 12 | stage("cleanup") { |
| 13 | sh("rm -rf * || true") |
chnyda | 0bae467 | 2017-06-20 13:39:35 +0200 | [diff] [blame] | 14 | } |
chnyda | 0bae467 | 2017-06-20 13:39:35 +0200 | [diff] [blame] | 15 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 16 | stage("checkout") { |
| 17 | git.checkoutGitRepository( |
| 18 | "libvirt-exporter-${version}", |
| 19 | "${SOURCE_URL}", |
| 20 | SOURCE_BRANCH, |
| 21 | SOURCE_CREDENTIALS, |
| 22 | true, |
| 23 | 30, |
| 24 | 1 |
| 25 | ) |
chnyda | 8fd09df | 2017-05-18 15:17:11 +0200 | [diff] [blame] | 26 | } |
chnyda | 0bae467 | 2017-06-20 13:39:35 +0200 | [diff] [blame] | 27 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 28 | stage("build binary") { |
| 29 | dir("libvirt-exporter-${version}") { |
| 30 | sh("sed -i 's/VERSION/${version}/g' debian/changelog && ./build_static.sh") |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | def img = dockerLib.getImage("tcpcloud/debian-build-ubuntu-${DIST}") |
| 35 | stage("build package") { |
| 36 | img.inside("-u root:root") { |
| 37 | sh("apt-get update && apt-get install ruby ruby-dev && gem install fpm") |
| 38 | sh("cd libvirt-exporter-${version} && scripts/build.py --package --version=\"${version}\" --platform=linux --arch=amd64") |
| 39 | } |
| 40 | archiveArtifacts artifacts: "libvirt-exporter-${version}/build/*.deb" |
| 41 | } |
| 42 | |
| 43 | if (UPLOAD_APTLY.toBoolean()) { |
| 44 | lock("aptly-api") { |
| 45 | stage("upload") { |
| 46 | def buildSteps = [:] |
| 47 | def debFiles = sh(script: "ls libvirt-exporter-${version}/build/*.deb", returnStdout: true) |
| 48 | def debFilesArray = debFiles.trim().tokenize() |
| 49 | def workspace = common.getWorkspace() |
| 50 | for (int i = 0; i < debFilesArray.size(); i++) { |
| 51 | def debFile = debFilesArray[i]; |
| 52 | buildSteps[debFiles[i]] = aptly.uploadPackageStep( |
| 53 | "${workspace}/"+debFile, |
| 54 | APTLY_URL, |
| 55 | APTLY_REPO, |
| 56 | true |
| 57 | ) |
| 58 | } |
| 59 | parallel buildSteps |
chnyda | 8fd09df | 2017-05-18 15:17:11 +0200 | [diff] [blame] | 60 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 61 | stage("publish") { |
| 62 | aptly.snapshotRepo(APTLY_URL, APTLY_REPO, timestamp) |
Jakub Josef | 01719f7 | 2018-03-26 12:28:49 +0200 | [diff] [blame] | 63 | retry(2){ |
| 64 | aptly.publish(APTLY_URL) |
| 65 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 66 | } |
chnyda | 8fd09df | 2017-05-18 15:17:11 +0200 | [diff] [blame] | 67 | } |
| 68 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 69 | |
| 70 | img.inside("-u root:root") { |
| 71 | sh("rm -rf * || true") |
| 72 | } |
| 73 | |
| 74 | } catch (Throwable e) { |
| 75 | // If there was an exception thrown, the build failed |
| 76 | currentBuild.result = "FAILURE" |
| 77 | currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message |
| 78 | throw e |
| 79 | } finally { |
| 80 | common.sendNotification(currentBuild.result,"",["slack"]) |
| 81 | |
| 82 | if (currentBuild.result != 'FAILURE') { |
| 83 | sh("rm -rf *") |
| 84 | } |
chnyda | 8fd09df | 2017-05-18 15:17:11 +0200 | [diff] [blame] | 85 | } |
chnyda | 8fd09df | 2017-05-18 15:17:11 +0200 | [diff] [blame] | 86 | } |
| 87 | } |