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 | } |
| 23 | def timestamp = common.getDatetime() |
| 24 | node("docker") { |
| 25 | try{ |
| 26 | stage("checkout") { |
| 27 | sh("rm -rf src || true") |
| 28 | dir("src") { |
| 29 | def pollBranches = [[name:SOURCE_BRANCH]] |
| 30 | if (debian_branch) { |
| 31 | pollBranches.add([name:DEBIAN_BRANCH]) |
| 32 | } |
| 33 | checkout changelog: true, poll: false, |
| 34 | scm: [$class: 'GitSCM', branches: pollBranches, doGenerateSubmoduleConfigurations: false, |
| 35 | extensions: [[$class: 'CleanCheckout']], submoduleCfg: [], userRemoteConfigs: [[credentialsId: SOURCE_CREDENTIALS, url: SOURCE_URL]]] |
| 36 | if (debian_branch){ |
| 37 | sh("git checkout "+DEBIAN_BRANCH) |
| 38 | } |
| 39 | } |
| 40 | debian.cleanup(OS+":"+DIST) |
| 41 | } |
| 42 | stage("build-source") { |
| 43 | debian.buildSource("src", OS+":"+DIST, snapshot, 'Jenkins', 'autobuild@mirantis.com', revisionPostfix) |
| 44 | archiveArtifacts artifacts: "build-area/*.dsc" |
| 45 | archiveArtifacts artifacts: "build-area/*_source.changes" |
| 46 | archiveArtifacts artifacts: "build-area/*.tar.*" |
| 47 | } |
| 48 | stage("build-binary") { |
| 49 | dsc = sh script: "ls build-area/*.dsc", returnStdout: true |
| 50 | debian.buildBinary( |
| 51 | dsc.trim(), |
| 52 | OS+":"+DIST, |
| 53 | EXTRA_REPO_URL, |
| 54 | EXTRA_REPO_KEY_URL |
| 55 | ) |
| 56 | archiveArtifacts artifacts: "build-area/*.deb" |
| 57 | } |
| 58 | stage("lintian") { |
| 59 | changes = sh script: "ls build-area/*_"+ARCH+".changes", returnStdout: true |
| 60 | try { |
| 61 | debian.runLintian(changes.trim(), OS, OS+":"+DIST) |
| 62 | } catch (Exception e) { |
| 63 | println "[WARN] Lintian returned non-zero exit status" |
| 64 | currentBuild.result = 'UNSTABLE' |
| 65 | } |
| 66 | } |
| 67 | lock("aptly-api") { |
| 68 | stage("upload") { |
| 69 | buildSteps = [:] |
| 70 | debFiles = sh script: "ls build-area/*.deb", returnStdout: true |
| 71 | for (file in debFiles.tokenize()) { |
| 72 | workspace = common.getWorkspace() |
| 73 | def fh = new File((workspace+"/"+file).trim()) |
| 74 | buildSteps[fh.name.split('_')[0]] = aptly.uploadPackageStep( |
| 75 | "build-area/"+fh.name, |
| 76 | APTLY_URL, |
| 77 | APTLY_REPO, |
| 78 | true |
| 79 | ) |
| 80 | } |
| 81 | parallel buildSteps |
| 82 | } |
| 83 | stage("publish") { |
| 84 | aptly.snapshotRepo(APTLY_URL, APTLY_REPO, timestamp) |
| 85 | aptly.publish(APTLY_URL) |
| 86 | } |
| 87 | } |
| 88 | } catch (Throwable e) { |
| 89 | // If there was an error or exception thrown, the build failed |
| 90 | currentBuild.result = "FAILURE" |
| 91 | throw e |
| 92 | } finally { |
| 93 | common.sendNotification(currentBuild.result,"",["slack"]) |
| 94 | } |
| 95 | } |