Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 1 | def common = new com.mirantis.mk.Common() |
| 2 | def aptly = new com.mirantis.mk.Aptly() |
| 3 | def debian = new com.mirantis.mk.Debian() |
| 4 | |
| 5 | def snapshot |
| 6 | try { |
| 7 | snapshot = DEBIAN_SNAPSHOT |
| 8 | } catch (MissingPropertyException e) { |
| 9 | snapshot = false |
| 10 | } |
| 11 | def debian_branch |
| 12 | try { |
| 13 | debian_branch = DEBIAN_BRANCH |
| 14 | } catch (MissingPropertyException e) { |
| 15 | debian_branch = null |
| 16 | } |
| 17 | def revisionPostfix |
| 18 | try { |
| 19 | revisionPostfix = REVISION_POSTFIX |
| 20 | } catch (MissingPropertyException e) { |
| 21 | revisionPostfix = null |
| 22 | } |
chnyda | a1bd1d2 | 2017-03-20 11:05:43 +0100 | [diff] [blame] | 23 | |
| 24 | def uploadPpa |
| 25 | try { |
chnyda | d3b0b4c | 2017-04-05 11:24:05 +0200 | [diff] [blame] | 26 | uploadPpa = UPLOAD_PPA.toBoolean() |
chnyda | a1bd1d2 | 2017-03-20 11:05:43 +0100 | [diff] [blame] | 27 | } catch (MissingPropertyException e) { |
| 28 | uploadPpa = null |
| 29 | } |
| 30 | |
Alexander Noskov | dda81dc | 2017-09-12 15:02:07 +0400 | [diff] [blame] | 31 | def lintianCheck |
| 32 | try { |
| 33 | lintianCheck = LINTIAN_CHECK.toBoolean() |
| 34 | } catch (MissingPropertyException e) { |
| 35 | lintianCheck = true |
| 36 | } |
| 37 | |
chnyda | a1bd1d2 | 2017-03-20 11:05:43 +0100 | [diff] [blame] | 38 | def uploadAptly |
| 39 | try { |
chnyda | d3b0b4c | 2017-04-05 11:24:05 +0200 | [diff] [blame] | 40 | uploadAptly = UPLOAD_APTLY.toBoolean() |
chnyda | a1bd1d2 | 2017-03-20 11:05:43 +0100 | [diff] [blame] | 41 | } catch (MissingPropertyException e) { |
| 42 | uploadAptly = true |
| 43 | } |
| 44 | |
Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 45 | def timestamp = common.getDatetime() |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 46 | timeout(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 Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 78 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 79 | 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 Iurchenko | 7762878 | 2018-01-02 12:00:56 +0200 | [diff] [blame] | 83 | if (common.validInputParam('SOURCE_REFSPEC')) { |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 84 | 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 Iurchenko | 7762878 | 2018-01-02 12:00:56 +0200 | [diff] [blame] | 87 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 88 | 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 Iurchenko | b389473 | 2018-01-04 23:30:27 +0200 | [diff] [blame] | 114 | } |
Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 115 | } |
| 116 | } |
Alexander Noskov | dda81dc | 2017-09-12 15:02:07 +0400 | [diff] [blame] | 117 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 118 | 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 |
chnyda | a1bd1d2 | 2017-03-20 11:05:43 +0100 | [diff] [blame] | 134 | } |
chnyda | a1bd1d2 | 2017-03-20 11:05:43 +0100 | [diff] [blame] | 135 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 136 | stage("publish") { |
| 137 | aptly.snapshotRepo(APTLY_URL, APTLY_REPO, timestamp) |
Jakub Josef | 01719f7 | 2018-03-26 12:28:49 +0200 | [diff] [blame] | 138 | retry(2){ |
| 139 | aptly.publish(APTLY_URL) |
| 140 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 141 | } |
chnyda | a1bd1d2 | 2017-03-20 11:05:43 +0100 | [diff] [blame] | 142 | } |
| 143 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 144 | if (uploadPpa) { |
| 145 | stage("upload launchpad") { |
| 146 | debian.importGpgKey("launchpad-private") |
| 147 | debian.uploadPpa(PPA, "build-area", "launchpad-private") |
| 148 | } |
Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 149 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 150 | } 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 Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 157 | } |
Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 158 | } |
Jakub Josef | d2efd7d | 2017-08-22 17:49:57 +0200 | [diff] [blame] | 159 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 160 | |