blob: 4220b7ac5fd066da858b4d3a22157c1d141a614e [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}
chnydaa1bd1d22017-03-20 11:05:43 +010023
24def uploadPpa
25try {
chnydad3b0b4c2017-04-05 11:24:05 +020026 uploadPpa = UPLOAD_PPA.toBoolean()
chnydaa1bd1d22017-03-20 11:05:43 +010027} catch (MissingPropertyException e) {
28 uploadPpa = null
29}
30
Alexander Noskovdda81dc2017-09-12 15:02:07 +040031def lintianCheck
32try {
33 lintianCheck = LINTIAN_CHECK.toBoolean()
34} catch (MissingPropertyException e) {
35 lintianCheck = true
36}
37
chnydaa1bd1d22017-03-20 11:05:43 +010038def uploadAptly
39try {
chnydad3b0b4c2017-04-05 11:24:05 +020040 uploadAptly = UPLOAD_APTLY.toBoolean()
chnydaa1bd1d22017-03-20 11:05:43 +010041} catch (MissingPropertyException e) {
42 uploadAptly = true
43}
44
Jakub Josefc5a223a2017-03-01 14:40:08 +010045def timestamp = common.getDatetime()
46node("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 Iurchenko77628782018-01-02 12:00:56 +020055 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 Josefc5a223a2017-03-01 14:40:08 +010063 checkout changelog: true, poll: false,
64 scm: [$class: 'GitSCM', branches: pollBranches, doGenerateSubmoduleConfigurations: false,
Oleg Iurchenko77628782018-01-02 12:00:56 +020065 extensions: extensions, submoduleCfg: [], userRemoteConfigs: userRemoteConfigs]
Jakub Josefc5a223a2017-03-01 14:40:08 +010066 if (debian_branch){
67 sh("git checkout "+DEBIAN_BRANCH)
68 }
69 }
70 debian.cleanup(OS+":"+DIST)
71 }
72 stage("build-source") {
Oleg Iurchenko77628782018-01-02 12:00:56 +020073 // If SOURCE_REFSPEC is defined refspec will be checked out to local branch and need to build it instead of origin branch.
74 if (common.validInputParam('SOURCE_REFSPEC')) {
75 debian.buildSource("src", OS+":"+DIST, snapshot, 'Jenkins', 'autobuild@mirantis.com', revisionPostfix, '')
76 } else {
77 debian.buildSource("src", OS+":"+DIST, snapshot, 'Jenkins', 'autobuild@mirantis.com', revisionPostfix)
78 }
Jakub Josefc5a223a2017-03-01 14:40:08 +010079 archiveArtifacts artifacts: "build-area/*.dsc"
80 archiveArtifacts artifacts: "build-area/*_source.changes"
81 archiveArtifacts artifacts: "build-area/*.tar.*"
82 }
83 stage("build-binary") {
84 dsc = sh script: "ls build-area/*.dsc", returnStdout: true
Jakub Josef342bbe12017-05-09 16:48:49 +020085 if(common.validInputParam("PRE_BUILD_SCRIPT")) {
Jakub Josefe42fd122017-05-10 14:24:42 +020086 writeFile([file:"pre_build_script.sh", text: env['PRE_BUILD_SCRIPT']])
Jakub Josef342bbe12017-05-09 16:48:49 +020087 }
Jakub Josefc5a223a2017-03-01 14:40:08 +010088 debian.buildBinary(
89 dsc.trim(),
90 OS+":"+DIST,
91 EXTRA_REPO_URL,
92 EXTRA_REPO_KEY_URL
93 )
94 archiveArtifacts artifacts: "build-area/*.deb"
95 }
Alexander Noskovdda81dc2017-09-12 15:02:07 +040096
97 if (lintianCheck) {
98 stage("lintian") {
99 changes = sh script: "ls build-area/*_"+ARCH+".changes", returnStdout: true
100 try {
101 debian.runLintian(changes.trim(), OS, OS+":"+DIST)
102 } catch (Exception e) {
103 println "[WARN] Lintian returned non-zero exit status"
104 currentBuild.result = 'UNSTABLE'
105 }
Jakub Josefc5a223a2017-03-01 14:40:08 +0100106 }
107 }
chnydaa1bd1d22017-03-20 11:05:43 +0100108
109 if (uploadAptly) {
110 lock("aptly-api") {
111 stage("upload") {
112 buildSteps = [:]
113 debFiles = sh script: "ls build-area/*.deb", returnStdout: true
114 for (file in debFiles.tokenize()) {
Jakub Josefc5a223a2017-03-01 14:40:08 +0100115 workspace = common.getWorkspace()
116 def fh = new File((workspace+"/"+file).trim())
117 buildSteps[fh.name.split('_')[0]] = aptly.uploadPackageStep(
chnydaa1bd1d22017-03-20 11:05:43 +0100118 "build-area/"+fh.name,
119 APTLY_URL,
120 APTLY_REPO,
121 true
122 )
123 }
124 parallel buildSteps
Jakub Josefc5a223a2017-03-01 14:40:08 +0100125 }
chnydaa1bd1d22017-03-20 11:05:43 +0100126
127 stage("publish") {
Jakub Josefc5a223a2017-03-01 14:40:08 +0100128 aptly.snapshotRepo(APTLY_URL, APTLY_REPO, timestamp)
129 aptly.publish(APTLY_URL)
chnydaa1bd1d22017-03-20 11:05:43 +0100130 }
131 }
132 }
133 if (uploadPpa) {
134 stage("upload launchpad") {
135 debian.importGpgKey("launchpad-private")
136 debian.uploadPpa(PPA, "build-area", "launchpad-private")
Jakub Josefc5a223a2017-03-01 14:40:08 +0100137 }
138 }
139 } catch (Throwable e) {
140 // If there was an error or exception thrown, the build failed
141 currentBuild.result = "FAILURE"
Jakub Josefd2efd7d2017-08-22 17:49:57 +0200142 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
Jakub Josefc5a223a2017-03-01 14:40:08 +0100143 throw e
144 } finally {
145 common.sendNotification(currentBuild.result,"",["slack"])
146 }
Jakub Josefd2efd7d2017-08-22 17:49:57 +0200147}