| 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() | 
|  | 46 | node("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 Iurchenko | 7762878 | 2018-01-02 12:00:56 +0200 | [diff] [blame] | 55 | 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 Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 63 | checkout changelog: true, poll: false, | 
|  | 64 | scm: [$class: 'GitSCM', branches: pollBranches, doGenerateSubmoduleConfigurations: false, | 
| Oleg Iurchenko | 7762878 | 2018-01-02 12:00:56 +0200 | [diff] [blame] | 65 | extensions: extensions,  submoduleCfg: [], userRemoteConfigs: userRemoteConfigs] | 
| Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 66 | if (debian_branch){ | 
| Oleg Iurchenko | b389473 | 2018-01-04 23:30:27 +0200 | [diff] [blame] | 67 | /* 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 Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 76 | } | 
|  | 77 | } | 
|  | 78 | debian.cleanup(OS+":"+DIST) | 
|  | 79 | } | 
|  | 80 | stage("build-source") { | 
| Oleg Iurchenko | 7762878 | 2018-01-02 12:00:56 +0200 | [diff] [blame] | 81 | // 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 Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 87 | 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 Josef | 342bbe1 | 2017-05-09 16:48:49 +0200 | [diff] [blame] | 93 | if(common.validInputParam("PRE_BUILD_SCRIPT")) { | 
| Jakub Josef | e42fd12 | 2017-05-10 14:24:42 +0200 | [diff] [blame] | 94 | writeFile([file:"pre_build_script.sh", text: env['PRE_BUILD_SCRIPT']]) | 
| Jakub Josef | 342bbe1 | 2017-05-09 16:48:49 +0200 | [diff] [blame] | 95 | } | 
| Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 96 | 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 Noskov | dda81dc | 2017-09-12 15:02:07 +0400 | [diff] [blame] | 104 |  | 
|  | 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 Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 114 | } | 
|  | 115 | } | 
| chnyda | a1bd1d2 | 2017-03-20 11:05:43 +0100 | [diff] [blame] | 116 |  | 
|  | 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 Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 123 | workspace = common.getWorkspace() | 
|  | 124 | def fh = new File((workspace+"/"+file).trim()) | 
|  | 125 | buildSteps[fh.name.split('_')[0]] = aptly.uploadPackageStep( | 
| chnyda | a1bd1d2 | 2017-03-20 11:05:43 +0100 | [diff] [blame] | 126 | "build-area/"+fh.name, | 
|  | 127 | APTLY_URL, | 
|  | 128 | APTLY_REPO, | 
|  | 129 | true | 
|  | 130 | ) | 
|  | 131 | } | 
|  | 132 | parallel buildSteps | 
| Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 133 | } | 
| chnyda | a1bd1d2 | 2017-03-20 11:05:43 +0100 | [diff] [blame] | 134 |  | 
|  | 135 | stage("publish") { | 
| Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 136 | aptly.snapshotRepo(APTLY_URL, APTLY_REPO, timestamp) | 
|  | 137 | aptly.publish(APTLY_URL) | 
| chnyda | a1bd1d2 | 2017-03-20 11:05:43 +0100 | [diff] [blame] | 138 | } | 
|  | 139 | } | 
|  | 140 | } | 
|  | 141 | if (uploadPpa) { | 
|  | 142 | stage("upload launchpad") { | 
|  | 143 | debian.importGpgKey("launchpad-private") | 
|  | 144 | debian.uploadPpa(PPA, "build-area", "launchpad-private") | 
| Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 145 | } | 
|  | 146 | } | 
|  | 147 | } catch (Throwable e) { | 
|  | 148 | // If there was an error or exception thrown, the build failed | 
|  | 149 | currentBuild.result = "FAILURE" | 
| Jakub Josef | d2efd7d | 2017-08-22 17:49:57 +0200 | [diff] [blame] | 150 | currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message | 
| Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 151 | throw e | 
|  | 152 | } finally { | 
|  | 153 | common.sendNotification(currentBuild.result,"",["slack"]) | 
|  | 154 | } | 
| Jakub Josef | d2efd7d | 2017-08-22 17:49:57 +0200 | [diff] [blame] | 155 | } |