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}") { |
| 29 | sh("sed -i 's/VERSION/${version}/g' debian/changelog") |
| 30 | sh("debuild -us -uc") |
| 31 | } |
| 32 | |
| 33 | archiveArtifacts artifacts: "*.deb" |
| 34 | } |
| 35 | |
| 36 | if (UPLOAD_APTLY.toBoolean()) { |
| 37 | lock("aptly-api") { |
| 38 | stage("upload") { |
| 39 | def buildSteps = [:] |
| 40 | def debFiles = sh script: "ls *.deb", returnStdout: true |
| 41 | def debFilesArray = debFiles.trim().tokenize() |
| 42 | def workspace = common.getWorkspace() |
| 43 | for (int i = 0; i < debFilesArray.size(); i++) { |
| 44 | def debFile = debFilesArray[i]; |
| 45 | buildSteps[debFiles[i]] = aptly.uploadPackageStep( |
| 46 | "${workspace}/"+debFile, |
| 47 | APTLY_URL, |
| 48 | APTLY_REPO, |
| 49 | true |
| 50 | ) |
| 51 | } |
| 52 | parallel buildSteps |
| 53 | } |
| 54 | stage("publish") { |
| 55 | aptly.snapshotRepo(APTLY_URL, APTLY_REPO, timestamp) |
| 56 | aptly.publish(APTLY_URL) |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | } catch (Throwable e) { |
| 62 | // If there was an exception thrown, the build failed |
| 63 | currentBuild.result = "FAILURE" |
| 64 | throw e |
| 65 | } finally { |
| 66 | common.sendNotification(currentBuild.result,"",["slack"]) |
| 67 | |
| 68 | if (currentBuild.result != 'FAILURE') { |
| 69 | sh("rm -rf *") |
| 70 | } |
| 71 | } |
| 72 | } |