blob: 5d1633919bbf521129bc83ac3495faa4e6ea61fb [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()
Jakub Josefa63f9862018-01-11 17:58:38 +010046timeout(time: 12, unit: 'HOURS') {
47 node("docker") {
48 try{
49 stage("checkout") {
50 sh("rm -rf src || true")
51 dir("src") {
52 def pollBranches = [[name:SOURCE_BRANCH]]
53 if (debian_branch) {
54 pollBranches.add([name:DEBIAN_BRANCH])
55 }
56 def extensions = [[$class: 'CleanCheckout']]
57 def userRemoteConfigs = [[credentialsId: SOURCE_CREDENTIALS, url: SOURCE_URL]]
58 // Checkout specified refspec to local branch
59 if (common.validInputParam('SOURCE_REFSPEC')) {
60 extensions.add([$class: 'BuildChooserSetting', buildChooser: [$class: 'GerritTriggerBuildChooser']])
61 extensions.add([$class: 'LocalBranch', localBranch: SOURCE_BRANCH])
62 userRemoteConfigs[0]['refspec'] = SOURCE_REFSPEC
63 }
64 checkout changelog: true, poll: false,
65 scm: [$class: 'GitSCM', branches: pollBranches, doGenerateSubmoduleConfigurations: false,
66 extensions: extensions, submoduleCfg: [], userRemoteConfigs: userRemoteConfigs]
67 if (debian_branch){
68 /* There are 2 schemas of build spec keeping:
69 1. Separate branch with build specs. I.e. debian/xenial
70 2. Separate directory with specs.
71 Logic below makes package build compatible with both schemas.
72 */
73 def retStatus = sh(script: 'git checkout ' + DEBIAN_BRANCH, returnStatus: true)
74 if (retStatus != 0) {
75 common.warningMsg("Cannot checkout ${DEBIAN_BRANCH} branch. Going to build package by ${SOURCE_BRANCH} branch.")
76 }
77 }
Jakub Josefc5a223a2017-03-01 14:40:08 +010078 }
Jakub Josefa63f9862018-01-11 17:58:38 +010079 debian.cleanup(OS+":"+DIST)
80 }
81 stage("build-source") {
82 // If SOURCE_REFSPEC is defined refspec will be checked out to local branch and need to build it instead of origin branch.
Oleg Iurchenko77628782018-01-02 12:00:56 +020083 if (common.validInputParam('SOURCE_REFSPEC')) {
Jakub Josefa63f9862018-01-11 17:58:38 +010084 debian.buildSource("src", OS+":"+DIST, snapshot, 'Jenkins', 'autobuild@mirantis.com', revisionPostfix, '')
85 } else {
86 debian.buildSource("src", OS+":"+DIST, snapshot, 'Jenkins', 'autobuild@mirantis.com', revisionPostfix)
Oleg Iurchenko77628782018-01-02 12:00:56 +020087 }
Jakub Josefa63f9862018-01-11 17:58:38 +010088 archiveArtifacts artifacts: "build-area/*.dsc"
89 archiveArtifacts artifacts: "build-area/*_source.changes"
90 archiveArtifacts artifacts: "build-area/*.tar.*"
91 }
92 stage("build-binary") {
93 dsc = sh script: "ls build-area/*.dsc", returnStdout: true
94 if(common.validInputParam("PRE_BUILD_SCRIPT")) {
95 writeFile([file:"pre_build_script.sh", text: env['PRE_BUILD_SCRIPT']])
96 }
97 debian.buildBinary(
98 dsc.trim(),
99 OS+":"+DIST,
100 EXTRA_REPO_URL,
101 EXTRA_REPO_KEY_URL
102 )
103 archiveArtifacts artifacts: "build-area/*.deb"
104 }
105
106 if (lintianCheck) {
107 stage("lintian") {
108 changes = sh script: "ls build-area/*_"+ARCH+".changes", returnStdout: true
109 try {
110 debian.runLintian(changes.trim(), OS, OS+":"+DIST)
111 } catch (Exception e) {
112 println "[WARN] Lintian returned non-zero exit status"
113 currentBuild.result = 'UNSTABLE'
Oleg Iurchenkob3894732018-01-04 23:30:27 +0200114 }
Jakub Josefc5a223a2017-03-01 14:40:08 +0100115 }
116 }
Alexander Noskovdda81dc2017-09-12 15:02:07 +0400117
Jakub Josefa63f9862018-01-11 17:58:38 +0100118 if (uploadAptly) {
119 lock("aptly-api") {
120 stage("upload") {
121 buildSteps = [:]
122 debFiles = sh script: "ls build-area/*.deb", returnStdout: true
123 for (file in debFiles.tokenize()) {
124 workspace = common.getWorkspace()
125 def fh = new File((workspace+"/"+file).trim())
126 buildSteps[fh.name.split('_')[0]] = aptly.uploadPackageStep(
127 "build-area/"+fh.name,
128 APTLY_URL,
129 APTLY_REPO,
130 true
131 )
132 }
133 parallel buildSteps
chnydaa1bd1d22017-03-20 11:05:43 +0100134 }
chnydaa1bd1d22017-03-20 11:05:43 +0100135
Jakub Josefa63f9862018-01-11 17:58:38 +0100136 stage("publish") {
137 aptly.snapshotRepo(APTLY_URL, APTLY_REPO, timestamp)
Jakub Josef01719f72018-03-26 12:28:49 +0200138 retry(2){
139 aptly.publish(APTLY_URL)
140 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100141 }
chnydaa1bd1d22017-03-20 11:05:43 +0100142 }
143 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100144 if (uploadPpa) {
145 stage("upload launchpad") {
146 debian.importGpgKey("launchpad-private")
147 debian.uploadPpa(PPA, "build-area", "launchpad-private")
148 }
Jakub Josefc5a223a2017-03-01 14:40:08 +0100149 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100150 } catch (Throwable e) {
151 // If there was an error or exception thrown, the build failed
152 currentBuild.result = "FAILURE"
153 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
154 throw e
155 } finally {
156 common.sendNotification(currentBuild.result,"",["slack"])
Jakub Josefc5a223a2017-03-01 14:40:08 +0100157 }
Jakub Josefc5a223a2017-03-01 14:40:08 +0100158 }
Jakub Josefd2efd7d2017-08-22 17:49:57 +0200159}
Jakub Josefa63f9862018-01-11 17:58:38 +0100160