blob: 58dfe571a5535e1a9f661b3d0fb93dfad61d23f7 [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}
23def timestamp = common.getDatetime()
24node("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}