blob: 864f0bc55c97d0cc420a1e1dab4431f1d61cefc7 [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]
Dmitry Burmistrov6a15b2e2018-08-14 13:11:51 +040067
68 /* There are 2 schemas of build spec keeping:
69 1. Separate directory with specs.
70 2. Separate branch with build specs. I.e. debian/xenial
71 Logic below makes package build compatible with both schemas.
72 */
73 if (fileExists('debian/changelog')) {
74 debian_branch = null
75 }
Jakub Josefa63f9862018-01-11 17:58:38 +010076 if (debian_branch){
Jakub Josefa63f9862018-01-11 17:58:38 +010077 def retStatus = sh(script: 'git checkout ' + DEBIAN_BRANCH, returnStatus: true)
78 if (retStatus != 0) {
79 common.warningMsg("Cannot checkout ${DEBIAN_BRANCH} branch. Going to build package by ${SOURCE_BRANCH} branch.")
80 }
81 }
Jakub Josefc5a223a2017-03-01 14:40:08 +010082 }
Jakub Josefa63f9862018-01-11 17:58:38 +010083 debian.cleanup(OS+":"+DIST)
84 }
85 stage("build-source") {
86 // 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 +020087 if (common.validInputParam('SOURCE_REFSPEC')) {
Jakub Josefa63f9862018-01-11 17:58:38 +010088 debian.buildSource("src", OS+":"+DIST, snapshot, 'Jenkins', 'autobuild@mirantis.com', revisionPostfix, '')
89 } else {
90 debian.buildSource("src", OS+":"+DIST, snapshot, 'Jenkins', 'autobuild@mirantis.com', revisionPostfix)
Oleg Iurchenko77628782018-01-02 12:00:56 +020091 }
Jakub Josefa63f9862018-01-11 17:58:38 +010092 archiveArtifacts artifacts: "build-area/*.dsc"
93 archiveArtifacts artifacts: "build-area/*_source.changes"
94 archiveArtifacts artifacts: "build-area/*.tar.*"
95 }
96 stage("build-binary") {
97 dsc = sh script: "ls build-area/*.dsc", returnStdout: true
98 if(common.validInputParam("PRE_BUILD_SCRIPT")) {
99 writeFile([file:"pre_build_script.sh", text: env['PRE_BUILD_SCRIPT']])
100 }
101 debian.buildBinary(
102 dsc.trim(),
103 OS+":"+DIST,
104 EXTRA_REPO_URL,
105 EXTRA_REPO_KEY_URL
106 )
107 archiveArtifacts artifacts: "build-area/*.deb"
108 }
109
110 if (lintianCheck) {
111 stage("lintian") {
112 changes = sh script: "ls build-area/*_"+ARCH+".changes", returnStdout: true
113 try {
114 debian.runLintian(changes.trim(), OS, OS+":"+DIST)
115 } catch (Exception e) {
116 println "[WARN] Lintian returned non-zero exit status"
117 currentBuild.result = 'UNSTABLE'
Oleg Iurchenkob3894732018-01-04 23:30:27 +0200118 }
Jakub Josefc5a223a2017-03-01 14:40:08 +0100119 }
120 }
Alexander Noskovdda81dc2017-09-12 15:02:07 +0400121
Jakub Josefa63f9862018-01-11 17:58:38 +0100122 if (uploadAptly) {
123 lock("aptly-api") {
124 stage("upload") {
125 buildSteps = [:]
126 debFiles = sh script: "ls build-area/*.deb", returnStdout: true
127 for (file in debFiles.tokenize()) {
128 workspace = common.getWorkspace()
129 def fh = new File((workspace+"/"+file).trim())
130 buildSteps[fh.name.split('_')[0]] = aptly.uploadPackageStep(
131 "build-area/"+fh.name,
132 APTLY_URL,
133 APTLY_REPO,
134 true
135 )
136 }
137 parallel buildSteps
chnydaa1bd1d22017-03-20 11:05:43 +0100138 }
chnydaa1bd1d22017-03-20 11:05:43 +0100139
Jakub Josefa63f9862018-01-11 17:58:38 +0100140 stage("publish") {
141 aptly.snapshotRepo(APTLY_URL, APTLY_REPO, timestamp)
Jakub Josef01719f72018-03-26 12:28:49 +0200142 retry(2){
143 aptly.publish(APTLY_URL)
144 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100145 }
chnydaa1bd1d22017-03-20 11:05:43 +0100146 }
147 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100148 if (uploadPpa) {
149 stage("upload launchpad") {
150 debian.importGpgKey("launchpad-private")
151 debian.uploadPpa(PPA, "build-area", "launchpad-private")
152 }
Jakub Josefc5a223a2017-03-01 14:40:08 +0100153 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100154 } catch (Throwable e) {
155 // If there was an error or exception thrown, the build failed
156 currentBuild.result = "FAILURE"
157 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
158 throw e
159 } finally {
160 common.sendNotification(currentBuild.result,"",["slack"])
Jakub Josefc5a223a2017-03-01 14:40:08 +0100161 }
Jakub Josefc5a223a2017-03-01 14:40:08 +0100162 }
Jakub Josefd2efd7d2017-08-22 17:49:57 +0200163}
Jakub Josefa63f9862018-01-11 17:58:38 +0100164