blob: 4c3f732d50ec9f5a8933fa9eef9532112c094d79 [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)
Jakub Josef01719f72018-03-26 12:28:49 +020063 retry(2){
64 aptly.publish(APTLY_URL)
65 }
Jakub Josefa63f9862018-01-11 17:58:38 +010066 }
chnyda8fd09df2017-05-18 15:17:11 +020067 }
68 }
Jakub Josefa63f9862018-01-11 17:58:38 +010069
70 img.inside("-u root:root") {
71 sh("rm -rf * || true")
72 }
73
74 } catch (Throwable e) {
75 // If there was an exception thrown, the build failed
76 currentBuild.result = "FAILURE"
77 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
78 throw e
79 } finally {
80 common.sendNotification(currentBuild.result,"",["slack"])
81
82 if (currentBuild.result != 'FAILURE') {
83 sh("rm -rf *")
84 }
chnyda8fd09df2017-05-18 15:17:11 +020085 }
chnyda8fd09df2017-05-18 15:17:11 +020086 }
87}