blob: 9e409447cf149bad03337438664cb24bdcd70138 [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 {
chnydad3b0b4c2017-04-05 11:24:05 +020026 uploadPpa = UPLOAD_PPA.toBoolean()
chnydaa1bd1d22017-03-20 11:05:43 +010027} catch (MissingPropertyException e) {
28 uploadPpa = null
29}
30
31def uploadAptly
32try {
chnydad3b0b4c2017-04-05 11:24:05 +020033 uploadAptly = UPLOAD_APTLY.toBoolean()
chnydaa1bd1d22017-03-20 11:05:43 +010034} 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
Jakub Josef342bbe12017-05-09 16:48:49 +020065 if(common.validInputParam("PRE_BUILD_SCRIPT")) {
Jakub Josefe42fd122017-05-10 14:24:42 +020066 writeFile([file:"pre_build_script.sh", text: env['PRE_BUILD_SCRIPT']])
Jakub Josef342bbe12017-05-09 16:48:49 +020067 }
Jakub Josefc5a223a2017-03-01 14:40:08 +010068 debian.buildBinary(
69 dsc.trim(),
70 OS+":"+DIST,
71 EXTRA_REPO_URL,
72 EXTRA_REPO_KEY_URL
73 )
74 archiveArtifacts artifacts: "build-area/*.deb"
75 }
76 stage("lintian") {
77 changes = sh script: "ls build-area/*_"+ARCH+".changes", returnStdout: true
78 try {
79 debian.runLintian(changes.trim(), OS, OS+":"+DIST)
80 } catch (Exception e) {
81 println "[WARN] Lintian returned non-zero exit status"
82 currentBuild.result = 'UNSTABLE'
83 }
84 }
chnydaa1bd1d22017-03-20 11:05:43 +010085
86 if (uploadAptly) {
87 lock("aptly-api") {
88 stage("upload") {
89 buildSteps = [:]
90 debFiles = sh script: "ls build-area/*.deb", returnStdout: true
91 for (file in debFiles.tokenize()) {
Jakub Josefc5a223a2017-03-01 14:40:08 +010092 workspace = common.getWorkspace()
93 def fh = new File((workspace+"/"+file).trim())
94 buildSteps[fh.name.split('_')[0]] = aptly.uploadPackageStep(
chnydaa1bd1d22017-03-20 11:05:43 +010095 "build-area/"+fh.name,
96 APTLY_URL,
97 APTLY_REPO,
98 true
99 )
100 }
101 parallel buildSteps
Jakub Josefc5a223a2017-03-01 14:40:08 +0100102 }
chnydaa1bd1d22017-03-20 11:05:43 +0100103
104 stage("publish") {
Jakub Josefc5a223a2017-03-01 14:40:08 +0100105 aptly.snapshotRepo(APTLY_URL, APTLY_REPO, timestamp)
106 aptly.publish(APTLY_URL)
chnydaa1bd1d22017-03-20 11:05:43 +0100107 }
108 }
109 }
110 if (uploadPpa) {
111 stage("upload launchpad") {
112 debian.importGpgKey("launchpad-private")
113 debian.uploadPpa(PPA, "build-area", "launchpad-private")
Jakub Josefc5a223a2017-03-01 14:40:08 +0100114 }
115 }
116 } catch (Throwable e) {
117 // If there was an error or exception thrown, the build failed
118 currentBuild.result = "FAILURE"
Jakub Josefd2efd7d2017-08-22 17:49:57 +0200119 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
Jakub Josefc5a223a2017-03-01 14:40:08 +0100120 throw e
121 } finally {
122 common.sendNotification(currentBuild.result,"",["slack"])
123 }
Jakub Josefd2efd7d2017-08-22 17:49:57 +0200124}