blob: f9966353775e799e15d7baa9efda3ac2ba97c9ba [file] [log] [blame]
chnydaa8d16342017-06-20 17:18:25 +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()
6
7node('docker') {
8 try{
9
10 stage("cleanup") {
11 sh("rm -rf * || true")
12 }
13
14 stage("checkout") {
15 git.checkoutGitRepository(
16 "jmx-exporter-${timestamp}",
17 "${SOURCE_URL}",
18 SOURCE_BRANCH,
19 SOURCE_CREDENTIALS,
20 true,
21 30,
22 1
23 )
24 }
25
26 try {
27 def img = docker.img("tcpcloud/debian-build-ubuntu-xenial")
28
29 img.inside {
30 stage("Build") {
31 sh("sed -i \"s/TIMESTAMP/${timestamp}/g\" \$(find -name pom.xml)")
32 sh("sudo apt-get update && sudo apt-get install -y openjdk-8-jdk maven")
33 sh("cd jmx-exporter-${timestamp} && mvn package")
34 }
35 }
36
37 if (UPLOAD_APTLY.toBoolean()) {
38 stage("upload package") {
39 def buildSteps = [:]
40 def debFiles = sh script: "find -name *.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
55 stage("publish") {
56 aptly.snapshotRepo(APTLY_URL, APTLY_REPO, timestamp)
57 aptly.publish(APTLY_URL)
58 }
59 }
60
61 } catch (Exception e) {
62 currentBuild.result = 'FAILURE'
63 println "Cleaning up docker images"
64 sh("docker images | grep -E '[-:\\ ]+${timestamp}[\\.\\ /\$]+' | awk '{print \$3}' | xargs docker rmi -f || true")
65 throw e
66 }
67
68 } catch (Throwable e) {
69 // If there was an exception thrown, the build failed
70 currentBuild.result = "FAILURE"
71 throw e
72 } finally {
73 common.sendNotification(currentBuild.result,"",["slack"])
74
75 if (currentBuild.result != 'FAILURE') {
76 sh("rm -rf *")
77 }
78 }
79}