blob: e9ac9815fc8d85946f97f853cf437a802c363a4c [file] [log] [blame]
Jakub Josefc5a223a2017-03-01 14:40:08 +01001def common = new com.mirantis.mk.Common()
2def aptly = new com.mirantis.mk.Aptly()
chnyda2cccb452017-04-07 11:34:57 +02003def git = new com.mirantis.mk.Git()
Jakub Josefc5a223a2017-03-01 14:40:08 +01004def timestamp = common.getDatetime()
5
chnyda2cccb452017-04-07 11:34:57 +02006def binaryPackages
7try {
8 binaryPackages = BINARY_PACKAGES
9} catch (MissingPropertyException e) {
10 binaryPackages = ""
11}
Jakub Josefa63f9862018-01-11 17:58:38 +010012timeout(time: 12, unit: 'HOURS') {
13 node("docker") {
14 try {
15 def workspace = common.getWorkspace()
16 stage("checkout") {
17 sh("test -d debs && rm -rf debs || true")
18 sh("test -d build && rm -rf build || true")
19 git.checkoutGitRepository(
20 ".",
21 SOURCE_URL,
22 SOURCE_BRANCH,
23 SOURCE_CREDENTIALS,
24 false,
25 30,
26 1
27 )
chnyda2cccb452017-04-07 11:34:57 +020028 }
Jakub Josefa63f9862018-01-11 17:58:38 +010029 stage("build") {
30 if (binaryPackages == "all" || binaryPackages == "") {
31 sh("docker run -v " + workspace + ":" + workspace + " -w " + workspace + " --rm=true --privileged "+OS+":" + DIST +
32 " /bin/bash -c 'apt-get update && apt-get install -y packaging-dev && ./build-debs.sh " + DIST + "'")
33 } else {
34 sh("docker run -v " + workspace + ":" + workspace + " -w " + workspace + " --rm=true --privileged "+OS+":" + DIST +
35 " /bin/bash -c 'apt-get update && apt-get install -y packaging-dev && ./build-debs.sh " + DIST + " " + binaryPackages + "'")
Jakub Josefc5a223a2017-03-01 14:40:08 +010036 }
Jakub Josefa63f9862018-01-11 17:58:38 +010037 archiveArtifacts artifacts: "debs/${DIST}-${ARCH}/*.deb"
Jakub Josefc5a223a2017-03-01 14:40:08 +010038 }
Jakub Josefa63f9862018-01-11 17:58:38 +010039 lock("aptly-api") {
40 stage("upload") {
41 buildSteps = [:]
42 debFiles = sh script: "ls debs/"+DIST+"-"+ARCH+"/*.deb", returnStdout: true
43 for (file in debFiles.tokenize()) {
44 def fh = new File((workspace+"/"+file).trim())
45 buildSteps[fh.name.split('_')[0]] = aptly.uploadPackageStep(
46 "debs/"+DIST+"-"+ARCH+"/"+fh.name,
47 APTLY_URL,
48 APTLY_REPO,
49 true
50 )
51 }
52 parallel buildSteps
53 }
54 stage("publish") {
55 aptly.snapshotRepo(APTLY_URL, APTLY_REPO, timestamp)
Jakub Josef01719f72018-03-26 12:28:49 +020056 retry(2){
57 aptly.publish(APTLY_URL)
58 }
Jakub Josefa63f9862018-01-11 17:58:38 +010059 }
60 }
61 } catch (Throwable e) {
62 // If there was an error or exception thrown, the build failed
63 currentBuild.result = "FAILURE"
64 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
65 throw e
66 } finally {
67 common.sendNotification(currentBuild.result,"",["slack"])
Jakub Josefc5a223a2017-03-01 14:40:08 +010068 }
Jakub Josefa63f9862018-01-11 17:58:38 +010069 }
Jakub Josefd2efd7d2017-08-22 17:49:57 +020070}