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 | } |
| 55 | checkout changelog: true, poll: false, |
| 56 | scm: [$class: 'GitSCM', branches: pollBranches, doGenerateSubmoduleConfigurations: false, |
| 57 | extensions: [[$class: 'CleanCheckout']], submoduleCfg: [], userRemoteConfigs: [[credentialsId: SOURCE_CREDENTIALS, url: SOURCE_URL]]] |
| 58 | if (debian_branch){ |
| 59 | sh("git checkout "+DEBIAN_BRANCH) |
| 60 | } |
| 61 | } |
| 62 | debian.cleanup(OS+":"+DIST) |
| 63 | } |
| 64 | stage("build-source") { |
| 65 | debian.buildSource("src", OS+":"+DIST, snapshot, 'Jenkins', 'autobuild@mirantis.com', revisionPostfix) |
| 66 | archiveArtifacts artifacts: "build-area/*.dsc" |
| 67 | archiveArtifacts artifacts: "build-area/*_source.changes" |
| 68 | archiveArtifacts artifacts: "build-area/*.tar.*" |
| 69 | } |
| 70 | stage("build-binary") { |
| 71 | dsc = sh script: "ls build-area/*.dsc", returnStdout: true |
Jakub Josef | 342bbe1 | 2017-05-09 16:48:49 +0200 | [diff] [blame] | 72 | if(common.validInputParam("PRE_BUILD_SCRIPT")) { |
Jakub Josef | e42fd12 | 2017-05-10 14:24:42 +0200 | [diff] [blame] | 73 | writeFile([file:"pre_build_script.sh", text: env['PRE_BUILD_SCRIPT']]) |
Jakub Josef | 342bbe1 | 2017-05-09 16:48:49 +0200 | [diff] [blame] | 74 | } |
Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 75 | debian.buildBinary( |
| 76 | dsc.trim(), |
| 77 | OS+":"+DIST, |
| 78 | EXTRA_REPO_URL, |
| 79 | EXTRA_REPO_KEY_URL |
| 80 | ) |
| 81 | archiveArtifacts artifacts: "build-area/*.deb" |
| 82 | } |
Alexander Noskov | dda81dc | 2017-09-12 15:02:07 +0400 | [diff] [blame^] | 83 | |
| 84 | if (lintianCheck) { |
| 85 | stage("lintian") { |
| 86 | changes = sh script: "ls build-area/*_"+ARCH+".changes", returnStdout: true |
| 87 | try { |
| 88 | debian.runLintian(changes.trim(), OS, OS+":"+DIST) |
| 89 | } catch (Exception e) { |
| 90 | println "[WARN] Lintian returned non-zero exit status" |
| 91 | currentBuild.result = 'UNSTABLE' |
| 92 | } |
Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 93 | } |
| 94 | } |
chnyda | a1bd1d2 | 2017-03-20 11:05:43 +0100 | [diff] [blame] | 95 | |
| 96 | if (uploadAptly) { |
| 97 | lock("aptly-api") { |
| 98 | stage("upload") { |
| 99 | buildSteps = [:] |
| 100 | debFiles = sh script: "ls build-area/*.deb", returnStdout: true |
| 101 | for (file in debFiles.tokenize()) { |
Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 102 | workspace = common.getWorkspace() |
| 103 | def fh = new File((workspace+"/"+file).trim()) |
| 104 | buildSteps[fh.name.split('_')[0]] = aptly.uploadPackageStep( |
chnyda | a1bd1d2 | 2017-03-20 11:05:43 +0100 | [diff] [blame] | 105 | "build-area/"+fh.name, |
| 106 | APTLY_URL, |
| 107 | APTLY_REPO, |
| 108 | true |
| 109 | ) |
| 110 | } |
| 111 | parallel buildSteps |
Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 112 | } |
chnyda | a1bd1d2 | 2017-03-20 11:05:43 +0100 | [diff] [blame] | 113 | |
| 114 | stage("publish") { |
Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 115 | aptly.snapshotRepo(APTLY_URL, APTLY_REPO, timestamp) |
| 116 | aptly.publish(APTLY_URL) |
chnyda | a1bd1d2 | 2017-03-20 11:05:43 +0100 | [diff] [blame] | 117 | } |
| 118 | } |
| 119 | } |
| 120 | if (uploadPpa) { |
| 121 | stage("upload launchpad") { |
| 122 | debian.importGpgKey("launchpad-private") |
| 123 | debian.uploadPpa(PPA, "build-area", "launchpad-private") |
Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 124 | } |
| 125 | } |
| 126 | } catch (Throwable e) { |
| 127 | // If there was an error or exception thrown, the build failed |
| 128 | currentBuild.result = "FAILURE" |
Jakub Josef | d2efd7d | 2017-08-22 17:49:57 +0200 | [diff] [blame] | 129 | currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message |
Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 130 | throw e |
| 131 | } finally { |
| 132 | common.sendNotification(currentBuild.result,"",["slack"]) |
| 133 | } |
Jakub Josef | d2efd7d | 2017-08-22 17:49:57 +0200 | [diff] [blame] | 134 | } |