blob: 8bfbff6a8c15910fd59120b5ad6a23e788f23a2b [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 }
Oleg Iurchenko77628782018-01-02 12:00:56 +020055 def extensions = [[$class: 'CleanCheckout']]
56 def userRemoteConfigs = [[credentialsId: SOURCE_CREDENTIALS, url: SOURCE_URL]]
57 // Checkout specified refspec to local branch
58 if (common.validInputParam('SOURCE_REFSPEC')) {
59 extensions.add([$class: 'BuildChooserSetting', buildChooser: [$class: 'GerritTriggerBuildChooser']])
60 extensions.add([$class: 'LocalBranch', localBranch: SOURCE_BRANCH])
61 userRemoteConfigs[0]['refspec'] = SOURCE_REFSPEC
62 }
Jakub Josefc5a223a2017-03-01 14:40:08 +010063 checkout changelog: true, poll: false,
64 scm: [$class: 'GitSCM', branches: pollBranches, doGenerateSubmoduleConfigurations: false,
Oleg Iurchenko77628782018-01-02 12:00:56 +020065 extensions: extensions, submoduleCfg: [], userRemoteConfigs: userRemoteConfigs]
Jakub Josefc5a223a2017-03-01 14:40:08 +010066 if (debian_branch){
Oleg Iurchenkob3894732018-01-04 23:30:27 +020067 /* There are 2 schemas of build spec keeping:
68 1. Separate branch with build specs. I.e. debian/xenial
69 2. Separate directory with specs.
70 Logic below makes package build compatible with both schemas.
71 */
72 def retStatus = sh(script: 'git checkout ' + DEBIAN_BRANCH, returnStatus: true)
73 if (retStatus != 0) {
74 common.warningMsg("Cannot checkout ${DEBIAN_BRANCH} branch. Going to build package by ${SOURCE_BRANCH} branch.")
75 }
Jakub Josefc5a223a2017-03-01 14:40:08 +010076 }
77 }
78 debian.cleanup(OS+":"+DIST)
79 }
80 stage("build-source") {
Oleg Iurchenko77628782018-01-02 12:00:56 +020081 // If SOURCE_REFSPEC is defined refspec will be checked out to local branch and need to build it instead of origin branch.
82 if (common.validInputParam('SOURCE_REFSPEC')) {
83 debian.buildSource("src", OS+":"+DIST, snapshot, 'Jenkins', 'autobuild@mirantis.com', revisionPostfix, '')
84 } else {
85 debian.buildSource("src", OS+":"+DIST, snapshot, 'Jenkins', 'autobuild@mirantis.com', revisionPostfix)
86 }
Jakub Josefc5a223a2017-03-01 14:40:08 +010087 archiveArtifacts artifacts: "build-area/*.dsc"
88 archiveArtifacts artifacts: "build-area/*_source.changes"
89 archiveArtifacts artifacts: "build-area/*.tar.*"
90 }
91 stage("build-binary") {
92 dsc = sh script: "ls build-area/*.dsc", returnStdout: true
Jakub Josef342bbe12017-05-09 16:48:49 +020093 if(common.validInputParam("PRE_BUILD_SCRIPT")) {
Jakub Josefe42fd122017-05-10 14:24:42 +020094 writeFile([file:"pre_build_script.sh", text: env['PRE_BUILD_SCRIPT']])
Jakub Josef342bbe12017-05-09 16:48:49 +020095 }
Jakub Josefc5a223a2017-03-01 14:40:08 +010096 debian.buildBinary(
97 dsc.trim(),
98 OS+":"+DIST,
99 EXTRA_REPO_URL,
100 EXTRA_REPO_KEY_URL
101 )
102 archiveArtifacts artifacts: "build-area/*.deb"
103 }
Alexander Noskovdda81dc2017-09-12 15:02:07 +0400104
105 if (lintianCheck) {
106 stage("lintian") {
107 changes = sh script: "ls build-area/*_"+ARCH+".changes", returnStdout: true
108 try {
109 debian.runLintian(changes.trim(), OS, OS+":"+DIST)
110 } catch (Exception e) {
111 println "[WARN] Lintian returned non-zero exit status"
112 currentBuild.result = 'UNSTABLE'
113 }
Jakub Josefc5a223a2017-03-01 14:40:08 +0100114 }
115 }
chnydaa1bd1d22017-03-20 11:05:43 +0100116
117 if (uploadAptly) {
118 lock("aptly-api") {
119 stage("upload") {
120 buildSteps = [:]
121 debFiles = sh script: "ls build-area/*.deb", returnStdout: true
122 for (file in debFiles.tokenize()) {
Jakub Josefc5a223a2017-03-01 14:40:08 +0100123 workspace = common.getWorkspace()
124 def fh = new File((workspace+"/"+file).trim())
125 buildSteps[fh.name.split('_')[0]] = aptly.uploadPackageStep(
chnydaa1bd1d22017-03-20 11:05:43 +0100126 "build-area/"+fh.name,
127 APTLY_URL,
128 APTLY_REPO,
129 true
130 )
131 }
132 parallel buildSteps
Jakub Josefc5a223a2017-03-01 14:40:08 +0100133 }
chnydaa1bd1d22017-03-20 11:05:43 +0100134
135 stage("publish") {
Jakub Josefc5a223a2017-03-01 14:40:08 +0100136 aptly.snapshotRepo(APTLY_URL, APTLY_REPO, timestamp)
137 aptly.publish(APTLY_URL)
chnydaa1bd1d22017-03-20 11:05:43 +0100138 }
139 }
140 }
141 if (uploadPpa) {
142 stage("upload launchpad") {
143 debian.importGpgKey("launchpad-private")
144 debian.uploadPpa(PPA, "build-area", "launchpad-private")
Jakub Josefc5a223a2017-03-01 14:40:08 +0100145 }
146 }
147 } catch (Throwable e) {
148 // If there was an error or exception thrown, the build failed
149 currentBuild.result = "FAILURE"
Jakub Josefd2efd7d2017-08-22 17:49:57 +0200150 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
Jakub Josefc5a223a2017-03-01 14:40:08 +0100151 throw e
152 } finally {
153 common.sendNotification(currentBuild.result,"",["slack"])
154 }
Jakub Josefd2efd7d2017-08-22 17:49:57 +0200155}