blob: 20515043420d1b2a448590a8735c2b2ec26daedd [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()
chnyda0bae4672017-06-20 13:39:35 +02004def dockerLib = new com.mirantis.mk.Docker()
chnyda8fd09df2017-05-18 15:17:11 +02005
6def timestamp = common.getDatetime()
7def version = "0.1~${timestamp}"
Jakub Josefa63f9862018-01-11 17:58:38 +01008timeout(time: 12, unit: 'HOURS') {
9 node('docker') {
10 try{
chnyda8fd09df2017-05-18 15:17:11 +020011
Jakub Josefa63f9862018-01-11 17:58:38 +010012 stage("cleanup") {
13 sh("rm -rf * || true")
chnyda0bae4672017-06-20 13:39:35 +020014 }
chnyda0bae4672017-06-20 13:39:35 +020015
Jakub Josefa63f9862018-01-11 17:58:38 +010016 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 )
chnyda8fd09df2017-05-18 15:17:11 +020026 }
chnyda0bae4672017-06-20 13:39:35 +020027
Jakub Josefa63f9862018-01-11 17:58:38 +010028 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
chnyda8fd09df2017-05-18 15:17:11 +020060 }
Jakub Josefa63f9862018-01-11 17:58:38 +010061 stage("publish") {
62 aptly.snapshotRepo(APTLY_URL, APTLY_REPO, timestamp)
63 aptly.publish(APTLY_URL)
64 }
chnyda8fd09df2017-05-18 15:17:11 +020065 }
66 }
Jakub Josefa63f9862018-01-11 17:58:38 +010067
68 img.inside("-u root:root") {
69 sh("rm -rf * || true")
70 }
71
72 } catch (Throwable e) {
73 // If there was an exception thrown, the build failed
74 currentBuild.result = "FAILURE"
75 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
76 throw e
77 } finally {
78 common.sendNotification(currentBuild.result,"",["slack"])
79
80 if (currentBuild.result != 'FAILURE') {
81 sh("rm -rf *")
82 }
chnyda8fd09df2017-05-18 15:17:11 +020083 }
chnyda8fd09df2017-05-18 15:17:11 +020084 }
85}