blob: 0d9839f3a56838498756cc4d8d35f573e974d3b3 [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
Alexander Noskovdda81dc2017-09-12 15:02:07 +040031def lintianCheck
32try {
33 lintianCheck = LINTIAN_CHECK.toBoolean()
34} catch (MissingPropertyException e) {
35 lintianCheck = true
36}
37
chnydaa1bd1d22017-03-20 11:05:43 +010038def uploadAptly
39try {
chnydad3b0b4c2017-04-05 11:24:05 +020040 uploadAptly = UPLOAD_APTLY.toBoolean()
chnydaa1bd1d22017-03-20 11:05:43 +010041} catch (MissingPropertyException e) {
42 uploadAptly = true
43}
44
Jakub Josefc5a223a2017-03-01 14:40:08 +010045def timestamp = common.getDatetime()
46node("docker") {
47 try{
48 stage("checkout") {
49 sh("rm -rf src || true")
50 dir("src") {
51 def pollBranches = [[name:SOURCE_BRANCH]]
52 if (debian_branch) {
53 pollBranches.add([name:DEBIAN_BRANCH])
54 }
55 checkout changelog: true, poll: false,
56 scm: [$class: 'GitSCM', branches: pollBranches, doGenerateSubmoduleConfigurations: false,
57 extensions: [[$class: 'CleanCheckout']], submoduleCfg: [], userRemoteConfigs: [[credentialsId: SOURCE_CREDENTIALS, url: SOURCE_URL]]]
58 if (debian_branch){
59 sh("git checkout "+DEBIAN_BRANCH)
60 }
61 }
62 debian.cleanup(OS+":"+DIST)
63 }
64 stage("build-source") {
65 debian.buildSource("src", OS+":"+DIST, snapshot, 'Jenkins', 'autobuild@mirantis.com', revisionPostfix)
66 archiveArtifacts artifacts: "build-area/*.dsc"
67 archiveArtifacts artifacts: "build-area/*_source.changes"
68 archiveArtifacts artifacts: "build-area/*.tar.*"
69 }
70 stage("build-binary") {
71 dsc = sh script: "ls build-area/*.dsc", returnStdout: true
Jakub Josef342bbe12017-05-09 16:48:49 +020072 if(common.validInputParam("PRE_BUILD_SCRIPT")) {
Jakub Josefe42fd122017-05-10 14:24:42 +020073 writeFile([file:"pre_build_script.sh", text: env['PRE_BUILD_SCRIPT']])
Jakub Josef342bbe12017-05-09 16:48:49 +020074 }
Jakub Josefc5a223a2017-03-01 14:40:08 +010075 debian.buildBinary(
76 dsc.trim(),
77 OS+":"+DIST,
78 EXTRA_REPO_URL,
79 EXTRA_REPO_KEY_URL
80 )
81 archiveArtifacts artifacts: "build-area/*.deb"
82 }
Alexander Noskovdda81dc2017-09-12 15:02:07 +040083
84 if (lintianCheck) {
85 stage("lintian") {
86 changes = sh script: "ls build-area/*_"+ARCH+".changes", returnStdout: true
87 try {
88 debian.runLintian(changes.trim(), OS, OS+":"+DIST)
89 } catch (Exception e) {
90 println "[WARN] Lintian returned non-zero exit status"
91 currentBuild.result = 'UNSTABLE'
92 }
Jakub Josefc5a223a2017-03-01 14:40:08 +010093 }
94 }
chnydaa1bd1d22017-03-20 11:05:43 +010095
96 if (uploadAptly) {
97 lock("aptly-api") {
98 stage("upload") {
99 buildSteps = [:]
100 debFiles = sh script: "ls build-area/*.deb", returnStdout: true
101 for (file in debFiles.tokenize()) {
Jakub Josefc5a223a2017-03-01 14:40:08 +0100102 workspace = common.getWorkspace()
103 def fh = new File((workspace+"/"+file).trim())
104 buildSteps[fh.name.split('_')[0]] = aptly.uploadPackageStep(
chnydaa1bd1d22017-03-20 11:05:43 +0100105 "build-area/"+fh.name,
106 APTLY_URL,
107 APTLY_REPO,
108 true
109 )
110 }
111 parallel buildSteps
Jakub Josefc5a223a2017-03-01 14:40:08 +0100112 }
chnydaa1bd1d22017-03-20 11:05:43 +0100113
114 stage("publish") {
Jakub Josefc5a223a2017-03-01 14:40:08 +0100115 aptly.snapshotRepo(APTLY_URL, APTLY_REPO, timestamp)
116 aptly.publish(APTLY_URL)
chnydaa1bd1d22017-03-20 11:05:43 +0100117 }
118 }
119 }
120 if (uploadPpa) {
121 stage("upload launchpad") {
122 debian.importGpgKey("launchpad-private")
123 debian.uploadPpa(PPA, "build-area", "launchpad-private")
Jakub Josefc5a223a2017-03-01 14:40:08 +0100124 }
125 }
126 } catch (Throwable e) {
127 // If there was an error or exception thrown, the build failed
128 currentBuild.result = "FAILURE"
Jakub Josefd2efd7d2017-08-22 17:49:57 +0200129 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
Jakub Josefc5a223a2017-03-01 14:40:08 +0100130 throw e
131 } finally {
132 common.sendNotification(currentBuild.result,"",["slack"])
133 }
Jakub Josefd2efd7d2017-08-22 17:49:57 +0200134}