Krzysztof Szukiełojć | 8d6c7ae | 2017-09-11 14:00:40 +0200 | [diff] [blame] | 1 | def common = new com.mirantis.mk.Common() |
| 2 | def git = new com.mirantis.mk.Git() |
| 3 | def artifactory = new com.mirantis.mk.Artifactory() |
| 4 | def aptly = new com.mirantis.mk.Aptly() |
| 5 | |
| 6 | def timestamp = common.getDatetime() |
| 7 | def version = "0.1~${timestamp}" |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 8 | timeout(time: 12, unit: 'HOURS') { |
| 9 | node('docker') { |
| 10 | try{ |
Krzysztof Szukiełojć | 8d6c7ae | 2017-09-11 14:00:40 +0200 | [diff] [blame] | 11 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 12 | stage("cleanup") { |
| 13 | sh("rm -rf * || true") |
| 14 | } |
Krzysztof Szukiełojć | 8d6c7ae | 2017-09-11 14:00:40 +0200 | [diff] [blame] | 15 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 16 | def workingDir = "src/gerrit.mcp.mirantis.net/debian" |
| 17 | stage("checkout") { |
| 18 | git.checkoutGitRepository( |
| 19 | "${workingDir}/prometheus-relay", |
| 20 | "${SOURCE_URL}", |
| 21 | SOURCE_BRANCH, |
| 22 | SOURCE_CREDENTIALS, |
| 23 | true, |
| 24 | 30, |
| 25 | 1 |
Krzysztof Szukiełojć | ee8dc93 | 2017-09-13 20:01:00 +0200 | [diff] [blame] | 26 | ) |
| 27 | } |
Krzysztof Szukiełojć | 8d6c7ae | 2017-09-11 14:00:40 +0200 | [diff] [blame] | 28 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 29 | try { |
| 30 | |
| 31 | def jenkinsUID = sh ( |
| 32 | script: 'id -u', |
| 33 | returnStdout: true |
| 34 | ).trim() |
| 35 | def imgName = "${OS}-${DIST}-${ARCH}" |
| 36 | def img |
| 37 | |
| 38 | stage("build image") { |
| 39 | img = docker.build( |
| 40 | "${imgName}:${timestamp}", |
| 41 | [ |
| 42 | "--build-arg uid=${jenkinsUID}", |
| 43 | "--build-arg timestamp=${timestamp}", |
| 44 | "-f ${workingDir}/prometheus-relay/docker/${OS}-${DIST}-${ARCH}.Dockerfile", |
| 45 | "." |
| 46 | ].join(' ') |
| 47 | ) |
| 48 | } |
| 49 | stage("build package") { |
| 50 | img.inside{ |
| 51 | sh("""wget https://storage.googleapis.com/golang/go1.8.1.linux-amd64.tar.gz && |
| 52 | tar xf go1.8.1.linux-amd64.tar.gz && |
| 53 | export GOROOT=\$PWD/go && |
| 54 | export GOPATH=\$PWD && |
| 55 | export PATH=\$PATH:\$GOPATH/bin:\$GOROOT/bin && |
| 56 | cd src/gerrit.mcp.mirantis.net/debian/prometheus-relay && |
| 57 | make""") |
| 58 | } |
| 59 | archiveArtifacts artifacts: "${workingDir}/prometheus-relay/build/*.deb" |
| 60 | } |
| 61 | if (UPLOAD_APTLY.toBoolean()) { |
| 62 | lock("aptly-api") { |
| 63 | stage("upload") { |
| 64 | def buildSteps = [:] |
| 65 | def debFiles = sh script: "ls ${workingDir}/prometheus-relay/build/*.deb", returnStdout: true |
| 66 | def debFilesArray = debFiles.trim().tokenize() |
| 67 | def workspace = common.getWorkspace() |
| 68 | for (int i = 0; i < debFilesArray.size(); i++) { |
| 69 | |
| 70 | def debFile = debFilesArray[i]; |
| 71 | buildSteps[debFiles[i]] = aptly.uploadPackageStep( |
| 72 | "${workspace}/"+debFile, |
| 73 | APTLY_URL, |
| 74 | APTLY_REPO, |
| 75 | true |
| 76 | ) |
| 77 | } |
| 78 | parallel buildSteps |
Krzysztof Szukiełojć | 8d6c7ae | 2017-09-11 14:00:40 +0200 | [diff] [blame] | 79 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 80 | stage("publish") { |
| 81 | aptly.snapshotRepo(APTLY_URL, APTLY_REPO, timestamp) |
Jakub Josef | 01719f7 | 2018-03-26 12:28:49 +0200 | [diff] [blame] | 82 | retry(2){ |
| 83 | aptly.publish(APTLY_URL) |
| 84 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 85 | } |
Krzysztof Szukiełojć | 8d6c7ae | 2017-09-11 14:00:40 +0200 | [diff] [blame] | 86 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 87 | stage("rebuild docker images") { |
| 88 | build job: "docker-build-images-prometheus", parameters: [] |
| 89 | } |
Krzysztof Szukiełojć | 1035ef4 | 2017-09-14 10:11:18 +0200 | [diff] [blame] | 90 | } |
Krzysztof Szukiełojć | 8d6c7ae | 2017-09-11 14:00:40 +0200 | [diff] [blame] | 91 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 92 | |
| 93 | } catch (Exception e) { |
| 94 | currentBuild.result = 'FAILURE' |
| 95 | throw e |
Krzysztof Szukiełojć | 8d6c7ae | 2017-09-11 14:00:40 +0200 | [diff] [blame] | 96 | } |
| 97 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 98 | } catch (Throwable e) { |
| 99 | // If there was an exception thrown, the build failed |
| 100 | currentBuild.result = "FAILURE" |
| 101 | currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message |
| 102 | throw e |
| 103 | } finally { |
| 104 | common.sendNotification(currentBuild.result,"",["slack"]) |
| 105 | |
| 106 | if (currentBuild.result != 'FAILURE') { |
| 107 | sh("rm -rf *") |
| 108 | } |
Krzysztof Szukiełojć | 8d6c7ae | 2017-09-11 14:00:40 +0200 | [diff] [blame] | 109 | } |
Krzysztof Szukiełojć | 8d6c7ae | 2017-09-11 14:00:40 +0200 | [diff] [blame] | 110 | } |
| 111 | } |