2019-06-04 16:50:29 +00:00
|
|
|
def getVersion() {
|
2019-02-05 09:35:14 +00:00
|
|
|
def path = "${env.WORKSPACE}/VERSION"
|
|
|
|
return readFile(path).trim()
|
|
|
|
}
|
|
|
|
|
|
|
|
def branchName() {
|
|
|
|
return env.GIT_BRANCH.replaceAll(/.*origin\//, '')
|
|
|
|
}
|
|
|
|
|
|
|
|
def parentOrCurrentBuild() {
|
|
|
|
def c = currentBuild.rawBuild.getCause(hudson.model.Cause$UpstreamCause)
|
|
|
|
if (c == null) { return currentBuild }
|
|
|
|
return c.getUpstreamRun()
|
|
|
|
}
|
|
|
|
|
|
|
|
def timestamp() {
|
|
|
|
/* we use parent if available to make timestmaps consistent */
|
|
|
|
def now = new Date(parentOrCurrentBuild().timeInMillis)
|
|
|
|
return now.format('yyMMdd-HHmmss', TimeZone.getTimeZone('UTC'))
|
|
|
|
}
|
|
|
|
|
|
|
|
def gitCommit() {
|
|
|
|
return GIT_COMMIT.take(6)
|
|
|
|
}
|
|
|
|
|
2019-11-05 08:21:02 +00:00
|
|
|
def pkgFilename(type, ext, arch=null) {
|
|
|
|
/* the grep removes the null arch */
|
2019-09-13 17:16:13 +00:00
|
|
|
return [
|
|
|
|
"StatusIm", timestamp(), gitCommit(), type, arch,
|
2019-11-05 08:21:02 +00:00
|
|
|
].grep().join('-') + ".${ext}"
|
2019-02-05 09:35:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
def doGitRebase() {
|
2020-01-13 12:15:33 +00:00
|
|
|
if (!isPRBuild()) {
|
2019-06-07 14:49:36 +00:00
|
|
|
println 'Skipping rebase due for non-PR build...'
|
2019-03-21 13:37:08 +00:00
|
|
|
return
|
|
|
|
}
|
2019-05-15 15:43:09 +00:00
|
|
|
def rebaseBranch = 'develop'
|
2019-05-16 20:11:49 +00:00
|
|
|
if (env.CHANGE_TARGET) { /* This is available for PR builds */
|
|
|
|
rebaseBranch = env.CHANGE_TARGET
|
2019-05-15 15:43:09 +00:00
|
|
|
}
|
2019-02-05 09:35:14 +00:00
|
|
|
sh 'git status'
|
2019-05-15 15:43:09 +00:00
|
|
|
sh "git fetch --force origin ${rebaseBranch}:${rebaseBranch}"
|
2019-02-05 09:35:14 +00:00
|
|
|
try {
|
2019-05-15 15:43:09 +00:00
|
|
|
sh "git rebase ${rebaseBranch}"
|
2019-02-05 09:35:14 +00:00
|
|
|
} catch (e) {
|
|
|
|
sh 'git rebase --abort'
|
|
|
|
throw e
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
def genBuildNumber() {
|
|
|
|
def number = sh(
|
|
|
|
returnStdout: true,
|
2019-08-23 17:16:08 +00:00
|
|
|
script: "${env.WORKSPACE}/scripts/version/gen_build_no.sh"
|
2019-02-05 09:35:14 +00:00
|
|
|
).trim()
|
|
|
|
println "Build Number: ${number}"
|
|
|
|
return number
|
|
|
|
}
|
|
|
|
|
2019-06-04 16:50:29 +00:00
|
|
|
def readBuildNumber() {
|
|
|
|
def number = sh(
|
|
|
|
returnStdout: true,
|
2019-08-23 17:16:08 +00:00
|
|
|
script: "${env.WORKSPACE}/scripts/version/build_no.sh"
|
2020-01-23 13:34:21 +00:00
|
|
|
).trim()
|
2019-06-04 16:50:29 +00:00
|
|
|
return number
|
|
|
|
}
|
|
|
|
|
2019-02-05 09:35:14 +00:00
|
|
|
def getDirPath(path) {
|
|
|
|
return path.tokenize('/')[0..-2].join('/')
|
|
|
|
}
|
|
|
|
|
|
|
|
def getFilename(path) {
|
|
|
|
return path.tokenize('/')[-1]
|
|
|
|
}
|
|
|
|
|
|
|
|
def getEnv(build, envvar) {
|
|
|
|
return build.getBuildVariables().get(envvar)
|
|
|
|
}
|
|
|
|
|
|
|
|
def buildDuration() {
|
|
|
|
def duration = currentBuild.durationString
|
|
|
|
return '~' + duration.take(duration.lastIndexOf(' and counting'))
|
|
|
|
}
|
|
|
|
|
|
|
|
def pkgFind(glob) {
|
|
|
|
def fullGlob = "pkg/*${glob}"
|
|
|
|
def found = findFiles(glob: fullGlob)
|
|
|
|
if (found.size() == 0) {
|
|
|
|
sh 'ls -l pkg/'
|
|
|
|
error("File not found via glob: ${fullGlob} ${found.size()}")
|
|
|
|
}
|
|
|
|
return found[0].path
|
|
|
|
}
|
|
|
|
|
2020-01-13 12:15:33 +00:00
|
|
|
def isPRBuild() {
|
|
|
|
return env.JOB_NAME.startsWith('status-react/prs')
|
|
|
|
}
|
|
|
|
|
|
|
|
def isE2EBuild() {
|
|
|
|
return env.JOB_NAME.contains('e2e')
|
|
|
|
}
|
|
|
|
|
2019-02-05 09:35:14 +00:00
|
|
|
def getBuildType() {
|
|
|
|
def jobName = env.JOB_NAME
|
2020-01-13 12:15:33 +00:00
|
|
|
if (isE2EBuild()) {
|
2019-02-05 09:35:14 +00:00
|
|
|
return 'e2e'
|
|
|
|
}
|
2020-01-13 12:15:33 +00:00
|
|
|
if (isPRBuild()) {
|
2019-02-05 09:35:14 +00:00
|
|
|
return 'pr'
|
|
|
|
}
|
|
|
|
if (jobName.startsWith('status-react/nightly')) {
|
|
|
|
return 'nightly'
|
|
|
|
}
|
|
|
|
if (jobName.startsWith('status-react/release')) {
|
|
|
|
return 'release'
|
|
|
|
}
|
|
|
|
return params.BUILD_TYPE
|
|
|
|
}
|
|
|
|
|
|
|
|
def getParentRunEnv(name) {
|
|
|
|
def c = currentBuild.rawBuild.getCause(hudson.model.Cause$UpstreamCause)
|
|
|
|
if (c == null) { return null }
|
|
|
|
return c.getUpstreamRun().getEnvironment()[name]
|
|
|
|
}
|
|
|
|
|
|
|
|
def changeId() {
|
|
|
|
/* CHANGE_ID can be provided via the build parameters or from parent */
|
|
|
|
def changeId = env.CHANGE_ID
|
|
|
|
changeId = params.CHANGE_ID ? params.CHANGE_ID : changeId
|
|
|
|
changeId = getParentRunEnv('CHANGE_ID') ? getParentRunEnv('CHANGE_ID') : changeId
|
|
|
|
if (!changeId) {
|
|
|
|
println('This build is not related to a PR, CHANGE_ID missing.')
|
|
|
|
println('GitHub notification impossible, skipping...')
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
return changeId
|
|
|
|
}
|
|
|
|
|
2019-04-11 11:29:37 +00:00
|
|
|
def updateEnv(type) {
|
2019-07-17 11:41:18 +00:00
|
|
|
def envFile = "${env.WORKSPACE}/.env.jenkins"
|
2019-04-11 11:29:37 +00:00
|
|
|
/* select .env based on type of build */
|
2019-07-17 11:41:18 +00:00
|
|
|
if (['nightly', 'release', 'e2e'].contains(type)) {
|
|
|
|
envFile = "${env.WORKSPACE}/.env.${type}"
|
2019-04-11 11:29:37 +00:00
|
|
|
}
|
2019-07-17 11:41:18 +00:00
|
|
|
sh "ln -sf ${envFile} .env"
|
2019-04-11 11:29:37 +00:00
|
|
|
/* show contents for debugging purposes */
|
|
|
|
sh "cat ${envFile}"
|
|
|
|
}
|
|
|
|
|
2019-02-05 09:35:14 +00:00
|
|
|
return this
|