blob: 2b2785169087861cf5a537bb048c5c0ea459298d [file] [log] [blame]
chnyda8fd09df2017-05-18 15:17:11 +02001def common = new com.mirantis.mk.Common()
2def git = new com.mirantis.mk.Git()
3def aptly = new com.mirantis.mk.Aptly()
4
5def timestamp = common.getDatetime()
6def version = "0.1~${timestamp}"
7
8node('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 Bourdonc38769f2017-06-19 20:41:23 +020029 sh("""sed -i 's/VERSION/${version}/g' debian/changelog &&
30 scripts/build.py --package --version=\"${version}\" --platform=linux --arch=amd64""")
chnyda8fd09df2017-05-18 15:17:11 +020031 }
Olivier Bourdonc38769f2017-06-19 20:41:23 +020032 archiveArtifacts artifacts: "libvirt-exporter-${version}/build/*.deb"
chnyda8fd09df2017-05-18 15:17:11 +020033 }
chnyda8fd09df2017-05-18 15:17:11 +020034 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}