blob: 83a23fe7359bbc50aba3fb38b71689c191111b8c [file] [log] [blame]
Jakub Josefc5a223a2017-03-01 14:40:08 +01001def common = new com.mirantis.mk.Common()
2def aptly = new com.mirantis.mk.Aptly()
3def debian = new com.mirantis.mk.Debian()
4
5def snapshot
6try {
7 snapshot = DEBIAN_SNAPSHOT
8} catch (MissingPropertyException e) {
9 snapshot = false
10}
11def debian_branch
12try {
13 debian_branch = DEBIAN_BRANCH
14} catch (MissingPropertyException e) {
15 debian_branch = null
16}
17def revisionPostfix
18try {
19 revisionPostfix = REVISION_POSTFIX
20} catch (MissingPropertyException e) {
21 revisionPostfix = null
22}
chnydaa1bd1d22017-03-20 11:05:43 +010023
24def uploadPpa
25try {
26 uploadPpa = UPLOAD_PPA
27} catch (MissingPropertyException e) {
28 uploadPpa = null
29}
30
31def uploadAptly
32try {
33 uploadAptly = UPLOAD_APTLY
34} catch (MissingPropertyException e) {
35 uploadAptly = true
36}
37
Jakub Josefc5a223a2017-03-01 14:40:08 +010038def timestamp = common.getDatetime()
39node("docker") {
40 try{
41 stage("checkout") {
42 sh("rm -rf src || true")
43 dir("src") {
44 def pollBranches = [[name:SOURCE_BRANCH]]
45 if (debian_branch) {
46 pollBranches.add([name:DEBIAN_BRANCH])
47 }
48 checkout changelog: true, poll: false,
49 scm: [$class: 'GitSCM', branches: pollBranches, doGenerateSubmoduleConfigurations: false,
50 extensions: [[$class: 'CleanCheckout']], submoduleCfg: [], userRemoteConfigs: [[credentialsId: SOURCE_CREDENTIALS, url: SOURCE_URL]]]
51 if (debian_branch){
52 sh("git checkout "+DEBIAN_BRANCH)
53 }
54 }
55 debian.cleanup(OS+":"+DIST)
56 }
57 stage("build-source") {
58 debian.buildSource("src", OS+":"+DIST, snapshot, 'Jenkins', 'autobuild@mirantis.com', revisionPostfix)
59 archiveArtifacts artifacts: "build-area/*.dsc"
60 archiveArtifacts artifacts: "build-area/*_source.changes"
61 archiveArtifacts artifacts: "build-area/*.tar.*"
62 }
63 stage("build-binary") {
64 dsc = sh script: "ls build-area/*.dsc", returnStdout: true
65 debian.buildBinary(
66 dsc.trim(),
67 OS+":"+DIST,
68 EXTRA_REPO_URL,
69 EXTRA_REPO_KEY_URL
70 )
71 archiveArtifacts artifacts: "build-area/*.deb"
72 }
73 stage("lintian") {
74 changes = sh script: "ls build-area/*_"+ARCH+".changes", returnStdout: true
75 try {
76 debian.runLintian(changes.trim(), OS, OS+":"+DIST)
77 } catch (Exception e) {
78 println "[WARN] Lintian returned non-zero exit status"
79 currentBuild.result = 'UNSTABLE'
80 }
81 }
chnydaa1bd1d22017-03-20 11:05:43 +010082
83 if (uploadAptly) {
84 lock("aptly-api") {
85 stage("upload") {
86 buildSteps = [:]
87 debFiles = sh script: "ls build-area/*.deb", returnStdout: true
88 for (file in debFiles.tokenize()) {
Jakub Josefc5a223a2017-03-01 14:40:08 +010089 workspace = common.getWorkspace()
90 def fh = new File((workspace+"/"+file).trim())
91 buildSteps[fh.name.split('_')[0]] = aptly.uploadPackageStep(
chnydaa1bd1d22017-03-20 11:05:43 +010092 "build-area/"+fh.name,
93 APTLY_URL,
94 APTLY_REPO,
95 true
96 )
97 }
98 parallel buildSteps
Jakub Josefc5a223a2017-03-01 14:40:08 +010099 }
chnydaa1bd1d22017-03-20 11:05:43 +0100100
101 stage("publish") {
Jakub Josefc5a223a2017-03-01 14:40:08 +0100102 aptly.snapshotRepo(APTLY_URL, APTLY_REPO, timestamp)
103 aptly.publish(APTLY_URL)
chnydaa1bd1d22017-03-20 11:05:43 +0100104 }
105 }
106 }
107 if (uploadPpa) {
108 stage("upload launchpad") {
109 debian.importGpgKey("launchpad-private")
110 debian.uploadPpa(PPA, "build-area", "launchpad-private")
Jakub Josefc5a223a2017-03-01 14:40:08 +0100111 }
112 }
113 } catch (Throwable e) {
114 // If there was an error or exception thrown, the build failed
115 currentBuild.result = "FAILURE"
116 throw e
117 } finally {
118 common.sendNotification(currentBuild.result,"",["slack"])
119 }
120}