2018-07-12 03:51:56 +03:00
|
|
|
import groovy.json.JsonOutput
|
|
|
|
|
2017-12-01 05:48:39 +03:00
|
|
|
pipeline {
|
|
|
|
agent any
|
|
|
|
|
2017-12-09 02:13:41 +03:00
|
|
|
options {
|
|
|
|
ansiColor('xterm')
|
|
|
|
}
|
|
|
|
|
2017-12-01 05:48:39 +03:00
|
|
|
stages {
|
2018-07-12 03:51:56 +03:00
|
|
|
stage('pre-build') {
|
|
|
|
steps {
|
2018-07-27 03:35:37 +03:00
|
|
|
sh 'rm -rf ./dist ./tmp'
|
2018-07-12 03:51:56 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-01 05:48:39 +03:00
|
|
|
stage('build') {
|
|
|
|
steps {
|
2018-07-12 03:51:56 +03:00
|
|
|
script {
|
2018-07-13 02:38:34 +03:00
|
|
|
def baseAssetsPath = env.BASE_ASSETS_PATH
|
2019-11-19 02:36:54 +03:00
|
|
|
def shortlinkDomain = env.SHORTLINK_DOMAIN
|
2019-10-09 02:14:24 +03:00
|
|
|
def targetS3Bucket = env.TARGET_S3_BUCKET
|
2019-01-30 05:26:05 +03:00
|
|
|
def sentryDsn = env.SENTRY_DSN
|
|
|
|
def gaTrackingId = env.GA_TRACKING_ID
|
2018-07-13 02:53:59 +03:00
|
|
|
def smokeURL = env.SMOKE_URL
|
2018-08-02 02:28:30 +03:00
|
|
|
def reticulumServer = env.RETICULUM_SERVER
|
2019-08-02 04:31:07 +03:00
|
|
|
def thumbnailServer = env.THUMBNAIL_SERVER
|
2018-12-08 02:49:31 +03:00
|
|
|
def corsProxyServer = env.CORS_PROXY_SERVER
|
2018-12-29 04:13:29 +03:00
|
|
|
def nonCorsProxyDomains = env.NON_CORS_PROXY_DOMAINS
|
2018-07-13 02:51:12 +03:00
|
|
|
def slackURL = env.SLACK_URL
|
2020-12-16 01:39:27 +03:00
|
|
|
def buildNumber = env.BUILD_NUMBER
|
|
|
|
def jobName = env.JOB_NAME
|
|
|
|
def gitCommit = env.GIT_COMMIT
|
|
|
|
def disableDeploy = env.DISABLE_DEPLOY
|
2021-01-12 03:33:49 +03:00
|
|
|
def showQAPromoteCommand = env.SHOW_QA_PROMOTE_COMMAND
|
|
|
|
def qaBuildsSlackChannel = env.QA_BUILDS_SLACK_CHANNEL
|
2021-08-20 21:27:22 +03:00
|
|
|
def uploadsHost = env.UPLOADS_HOST
|
2018-07-13 00:58:32 +03:00
|
|
|
|
2020-12-16 01:39:27 +03:00
|
|
|
def habCommand = (
|
2020-12-16 01:46:53 +03:00
|
|
|
"/bin/bash scripts/hab-build-and-push.sh "
|
2020-12-16 01:39:27 +03:00
|
|
|
+ "\\\"${baseAssetsPath}\\\" "
|
|
|
|
+ "\\\"${shortlinkDomain}\\\" "
|
|
|
|
+ "\\\"${reticulumServer}\\\" "
|
|
|
|
+ "\\\"${thumbnailServer}\\\" "
|
|
|
|
+ "\\\"${corsProxyServer}\\\" "
|
|
|
|
+ "\\\"${nonCorsProxyDomains}\\\" "
|
|
|
|
+ "\\\"${targetS3Bucket}\\\" "
|
|
|
|
+ "\\\"${sentryDsn}\\\" "
|
|
|
|
+ "\\\"${gaTrackingId}\\\" "
|
|
|
|
+ "\\\"${buildNumber}\\\" "
|
|
|
|
+ "\\\"${gitCommit}\\\" "
|
|
|
|
+ "\\\"${disableDeploy}\\\" "
|
2021-08-20 21:27:22 +03:00
|
|
|
+ "\\\"${uploadsHost}\\\" "
|
2020-12-16 01:39:27 +03:00
|
|
|
)
|
|
|
|
runCommand(habCommand)
|
2018-07-13 02:50:04 +03:00
|
|
|
|
2021-01-06 01:04:55 +03:00
|
|
|
def s = $/eval 'ls -t results/*.hart | head -n 1'/$
|
2019-10-09 08:23:23 +03:00
|
|
|
def hart = sh(returnStdout: true, script: "${s}").trim()
|
2020-12-16 01:39:27 +03:00
|
|
|
|
2019-10-09 08:23:23 +03:00
|
|
|
s = $/eval 'tail -n +6 ${hart} | xzcat | tar tf - | grep IDENT'/$
|
|
|
|
def identPath = sh(returnStdout: true, script: "${s}").trim()
|
2020-12-16 01:39:27 +03:00
|
|
|
|
2019-10-09 08:23:23 +03:00
|
|
|
s = $/eval 'tail -n +6 ${hart} | xzcat | tar xf - "${identPath}" -O'/$
|
|
|
|
def packageIdent = sh(returnStdout: true, script: "${s}").trim()
|
|
|
|
def packageTimeVersion = packageIdent.tokenize('/')[3]
|
|
|
|
def (major, minor, version) = packageIdent.tokenize('/')[2].tokenize('.')
|
|
|
|
def hubsVersion = "${major}.${minor}.${version}.${packageTimeVersion}"
|
|
|
|
|
2021-01-06 01:05:14 +03:00
|
|
|
def gitMessage = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'[%an] %s'").trim()
|
|
|
|
def gitSha = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim()
|
|
|
|
|
2021-01-12 03:33:49 +03:00
|
|
|
if (showQAPromoteCommand == "true") {
|
2021-01-06 01:05:14 +03:00
|
|
|
def text = (
|
|
|
|
"*<http://localhost:8080/job/${jobName}/${buildNumber}|#${buildNumber}>* *${jobName}* " +
|
2021-01-12 03:33:49 +03:00
|
|
|
"<https://github.com/mozilla/hubs/commit/$gitSha|$gitSha> ${hubsVersion} " +
|
|
|
|
"Hubs: ```${gitSha} ${gitMessage}```\n" +
|
|
|
|
"${packageIdent} built and uploaded - to promote:\n" +
|
|
|
|
"`/mr promote-hubs-qa ${packageIdent}`"
|
2021-01-06 01:05:14 +03:00
|
|
|
)
|
2021-01-12 03:33:49 +03:00
|
|
|
sendSlackMessage(text, qaBuildsSlackChannel, ":gift:", slackURL)
|
2020-12-16 01:39:27 +03:00
|
|
|
} else {
|
|
|
|
def text = (
|
|
|
|
"*<http://localhost:8080/job/${jobName}/${buildNumber}|#${buildNumber}>* *${jobName}* " +
|
|
|
|
"<https://github.com/mozilla/hubs/commit/$gitSha|$gitSha> ${hubsVersion} " +
|
|
|
|
"Hubs: ```${gitSha} ${gitMessage}```\n" +
|
|
|
|
"<${smokeURL}?required_version=${hubsVersion}|Smoke Test> - to push:\n" +
|
|
|
|
"`/mr hubs deploy ${hubsVersion} s3://${targetS3Bucket}`"
|
|
|
|
)
|
2020-12-16 02:42:30 +03:00
|
|
|
sendSlackMessage(text, "#mr-builds", ":gift:", slackURL)
|
2020-12-16 01:39:27 +03:00
|
|
|
}
|
2018-07-12 03:51:56 +03:00
|
|
|
}
|
2017-12-01 05:48:39 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
post {
|
2020-12-16 01:39:27 +03:00
|
|
|
always {
|
|
|
|
deleteDir()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
def runCommand(command) {
|
|
|
|
sh "/usr/bin/script --return -c ${shellString(command)} /dev/null"
|
|
|
|
}
|
|
|
|
|
2020-12-16 02:42:30 +03:00
|
|
|
def sendSlackMessage(text, channel, icon, slackURL) {
|
2020-12-16 01:39:27 +03:00
|
|
|
def payload = 'payload=' + JsonOutput.toJson([
|
|
|
|
text : text,
|
|
|
|
channel : channel,
|
|
|
|
username : "buildbot",
|
|
|
|
icon_emoji: icon
|
|
|
|
])
|
|
|
|
sh "curl -X POST --data-urlencode ${shellString(payload)} ${slackURL}"
|
|
|
|
}
|
|
|
|
|
|
|
|
// From https://issues.jenkins-ci.org/browse/JENKINS-44231
|
|
|
|
|
|
|
|
// Given arbitrary string returns a strongly escaped shell string literal.
|
|
|
|
// I.e. it will be in single quotes which turns off interpolation of $(...), etc.
|
|
|
|
// E.g.: 1'2\3\'4 5"6 (groovy string) -> '1'\''2\3\'\''4 5"6' (groovy string which can be safely pasted into shell command).
|
|
|
|
def shellString(s) {
|
|
|
|
// Replace ' with '\'' (https://unix.stackexchange.com/a/187654/260156). Then enclose with '...'.
|
|
|
|
// 1) Why not replace \ with \\? Because '...' does not treat backslashes in a special way.
|
|
|
|
// 2) And why not use ANSI-C quoting? I.e. we could replace ' with \'
|
|
|
|
// and enclose using $'...' (https://stackoverflow.com/a/8254156/4839573).
|
|
|
|
// Because ANSI-C quoting is not yet supported by Dash (default shell in Ubuntu & Debian) (https://unix.stackexchange.com/a/371873).
|
|
|
|
'\'' + s.replace('\'', '\'\\\'\'') + '\''
|
2017-12-01 05:48:39 +03:00
|
|
|
}
|