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() |
| 4 | |
| 5 | def timestamp = common.getDatetime() |
| 6 | def version = "0.1~${timestamp}" |
| 7 | |
| 8 | node('docker') { |
| 9 | try{ |
| 10 | |
| 11 | stage("cleanup") { |
| 12 | sh("rm -rf * || true") |
| 13 | } |
| 14 | |
| 15 | stage("checkout") { |
| 16 | git.checkoutGitRepository( |
| 17 | "libvirt-exporter-${version}", |
| 18 | "${SOURCE_URL}", |
| 19 | SOURCE_BRANCH, |
| 20 | SOURCE_CREDENTIALS, |
| 21 | true, |
| 22 | 30, |
| 23 | 1 |
| 24 | ) |
| 25 | } |
| 26 | |
| 27 | stage("build binary") { |
| 28 | dir("libvirt-exporter-${version}") { |
Olivier Bourdon | c38769f | 2017-06-19 20:41:23 +0200 | [diff] [blame] | 29 | sh("""sed -i 's/VERSION/${version}/g' debian/changelog && |
| 30 | scripts/build.py --package --version=\"${version}\" --platform=linux --arch=amd64""") |
chnyda | 8fd09df | 2017-05-18 15:17:11 +0200 | [diff] [blame] | 31 | } |
Olivier Bourdon | c38769f | 2017-06-19 20:41:23 +0200 | [diff] [blame] | 32 | archiveArtifacts artifacts: "libvirt-exporter-${version}/build/*.deb" |
chnyda | 8fd09df | 2017-05-18 15:17:11 +0200 | [diff] [blame] | 33 | } |
chnyda | 8fd09df | 2017-05-18 15:17:11 +0200 | [diff] [blame] | 34 | if (UPLOAD_APTLY.toBoolean()) { |
| 35 | lock("aptly-api") { |
| 36 | stage("upload") { |
| 37 | def buildSteps = [:] |
| 38 | def debFiles = sh script: "ls *.deb", returnStdout: true |
| 39 | def debFilesArray = debFiles.trim().tokenize() |
| 40 | def workspace = common.getWorkspace() |
| 41 | for (int i = 0; i < debFilesArray.size(); i++) { |
| 42 | def debFile = debFilesArray[i]; |
| 43 | buildSteps[debFiles[i]] = aptly.uploadPackageStep( |
| 44 | "${workspace}/"+debFile, |
| 45 | APTLY_URL, |
| 46 | APTLY_REPO, |
| 47 | true |
| 48 | ) |
| 49 | } |
| 50 | parallel buildSteps |
| 51 | } |
| 52 | stage("publish") { |
| 53 | aptly.snapshotRepo(APTLY_URL, APTLY_REPO, timestamp) |
| 54 | aptly.publish(APTLY_URL) |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | } catch (Throwable e) { |
| 60 | // If there was an exception thrown, the build failed |
| 61 | currentBuild.result = "FAILURE" |
| 62 | throw e |
| 63 | } finally { |
| 64 | common.sendNotification(currentBuild.result,"",["slack"]) |
| 65 | |
| 66 | if (currentBuild.result != 'FAILURE') { |
| 67 | sh("rm -rf *") |
| 68 | } |
| 69 | } |
| 70 | } |