blob: eb109cbb77eb9c6108b9fdf94bfc541b3d67372f [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}"
8
9node('docker') {
10 try{
11
12 stage("cleanup") {
13 sh("rm -rf * || true")
14 }
15
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 )
26 }
27
28 stage("build binary") {
29 dir("libvirt-exporter-${version}") {
chnyda0bae4672017-06-20 13:39:35 +020030 sh("sed -i 's/VERSION/${version}/g' debian/changelog && ./build_static.sh")
31 }
32 }
33
34 def img = dockerLib.getImage("tcpcloud/debian-build-ubuntu-xenial")
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")
chnyda8fd09df2017-05-18 15:17:11 +020039 }
Olivier Bourdonc38769f2017-06-19 20:41:23 +020040 archiveArtifacts artifacts: "libvirt-exporter-${version}/build/*.deb"
chnyda8fd09df2017-05-18 15:17:11 +020041 }
chnyda0bae4672017-06-20 13:39:35 +020042
chnyda8fd09df2017-05-18 15:17:11 +020043 if (UPLOAD_APTLY.toBoolean()) {
44 lock("aptly-api") {
45 stage("upload") {
46 def buildSteps = [:]
chnyda0bae4672017-06-20 13:39:35 +020047 def debFiles = sh(script: "ls libvirt-exporter-${version}/build/*.deb", returnStdout: true)
chnyda8fd09df2017-05-18 15:17:11 +020048 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
60 }
61 stage("publish") {
62 aptly.snapshotRepo(APTLY_URL, APTLY_REPO, timestamp)
63 aptly.publish(APTLY_URL)
64 }
65 }
66 }
67
chnyda0bae4672017-06-20 13:39:35 +020068 img.inside("-u root:root") {
69 sh("rm -rf * || true")
70 }
71
chnyda8fd09df2017-05-18 15:17:11 +020072 } catch (Throwable e) {
73 // If there was an exception thrown, the build failed
74 currentBuild.result = "FAILURE"
75 throw e
76 } finally {
77 common.sendNotification(currentBuild.result,"",["slack"])
78
79 if (currentBuild.result != 'FAILURE') {
80 sh("rm -rf *")
81 }
82 }
83}