jobs/build: use default target when job is triggered by timer

In a nightly build the job parameter TARGET stays on "selected...".
Thus, a check verifies if the job is triggered by a timer and then
takes the default target which is the first one in the file
'nwlTargets'.
With it the description name of the build gets a postfix 'nightly'.

Signed-off-by: Marc Mattmüller <marc.mattmueller@netmodule.com>
This commit is contained in:
Marc Mattmüller 2023-05-01 09:11:19 +02:00
parent 27c7777f79
commit a41f1b1148
1 changed files with 32 additions and 5 deletions

View File

@ -112,24 +112,51 @@ def printJobParameters() {
DEBUGGING = ${params.DEBUGGING}\n\
----------------------------------\n"
}
//---------------------------------------------------------------------------------------------------------------------
def isJobTriggeredByTimer() {
// The following check is not allowed without having an Administrator approved the script signature
// return (currentBuild.rawBuild.getCause(hudson.triggers.TimerTrigger$TimerTriggerCause) != null)
// Thus we need to find another way round with:
// CAUSE = "${currentBuild.getBuildCauses()[0].shortDescription}"
def jobCause = currentBuild.getBuildCauses()
println "jobCause as information:\n" + jobCause
def jobDescriptionString = "${jobCause[0].shortDescription}"
return jobDescriptionString.contains("timer")
}
//---------------------------------------------------------------------------------------------------------------------
def getDefaultTarget() {
def defaultTarget = sh(returnStdout: true, script: "head -n2 ./jobs/nwlTargets | tail -n1").trim()
return "${defaultTarget}"
}
//---------------------------------------------------------------------------------------------------------------------
def checkJobParameters() {
println "ToDo: Check if triggered by timer before throwing error"
// Check the selected target and overwrite it with a default one when triggered by a timer
def selectedTarget = "${params.TARGET}"
if("${params.TARGET}" == "select...") {
currentBuild.result = 'ABORTED'
error("Missing build target --> select parameter TARGET for a proper build")
selectedTarget = ""
if(isJobTriggeredByTimer()) {
selectedTarget = getDefaultTarget()
println "Triggered by Timer --> taking default target = ${selectedTarget}"
}
else {
currentBuild.result = 'ABORTED'
error("Missing build target --> select parameter TARGET for a proper build")
}
}
env.TARGET = "${selectedTarget}"
}
//---------------------------------------------------------------------------------------------------------------------
def setDisplayName() {
def buildName = "#${env.BUILD_NUMBER}"
currentBuild.displayName = "${buildName}-${params.TARGET}"
def postfix = isJobTriggeredByTimer() ? "-nightly" : ""
currentBuild.displayName = "${buildName}-${env.TARGET}${postfix}"
}
//---------------------------------------------------------------------------------------------------------------------
def setupEnvironment(commonHelpers) {
def machine = "${params.TARGET}"
def machine = "${env.TARGET}"
def nwlBranch = "${params.BUILD_BRANCH}"
def nwlRepoDir = "${env.YOCTO_REPO_DIR}"
commonHelpers.setupBuildEnvironment(machine, nwlBranch, nwlRepoDir, params.DEBUGGING)