jobs: rename and adapt Build Pipeline for building all targets

the pipeline was renamed to BuildAll and adatped to act as the
overall pipeline building all NWL targets.

Signed-off-by: Marc Mattmüller <marc.mattmueller@netmodule.com>
This commit is contained in:
Marc Mattmüller 2023-07-31 16:24:54 +02:00
parent cd76fd0385
commit 850e9f746e
1 changed files with 65 additions and 72 deletions

View File

@ -3,9 +3,6 @@
// So declare common (object created by the LOAD operation) outside the Node block.
def common
// Preloaded the list of supported targets used for the choice parameters TARGET:
def targetList
// This step is necessary to get the files directly from the git repo, as for the
// first build it is not yet cloned into the workspace. Normally we use an agent
// of a certain label (like core-os_buildagent) to have define credentials to get
@ -21,9 +18,6 @@ node() {
sh "git clone --depth 1 --branch main ssh://git@bitbucket.gad.local:7999/nm-nsp/nwl-ci.git ."
}
// get the list of the targets:
targetList = sh(returnStdout: true, script: "cat ./jobs/nwlTargets").trim()
// load common file
common = load "./jobs/Jenkinsfile_Common"
}
@ -35,10 +29,10 @@ pipeline {
agent any
parameters {
choice(name: 'TARGET', choices: "${targetList}", description: 'choose the build target')
string(name: 'BUILD_BRANCH', defaultValue: 'main', description: 'Enter the branch of the NWL to build (default = main), will skip deployment if not main')
booleanParam(name: 'CLEAN_BUILD', defaultValue: false, description: 'do a clean build, i.e. remove the yocto directory and start from scratch')
booleanParam(name: 'DEPLOY_TO_NEXUS', defaultValue: true, description: 'deploy the built artifact to Nexus')
booleanParam(name: 'SKIP_SSTATE_UPLOAD', defaultValue: false, description: 'skip uploading/synchronizing the sstate-cache to the mirror')
booleanParam(name: 'DEBUGGING', defaultValue: false, description: 'debugging mode, removes quiet mode for bitbake')
}
@ -60,8 +54,8 @@ pipeline {
steps {
script {
printJobParameters()
checkJobParameters()
setDisplayName()
checkJobParameters(common)
setDisplayName(common)
}
}
}
@ -81,22 +75,16 @@ pipeline {
stage('Build') {
steps {
script {
dir("${env.YOCTO_REPO_DIR}") {
common.buildTheYoctoPackage()
env.ARTIFACT_NAME = "NWL-${machine}.zip"
common.collectingPackageArtifacts("${env.MACHINE}")
common.packAndArchiveArtifacts("${env.MACHINE}", "${env.ARTIFACT_NAME}")
}
println "TODO: sync sstate-cache to the server"
}
}
}
def listOfTargets = getTargetsFromList()
stage('Deploy') {
when { expression { return (params.DEPLOY_TO_NEXUS && common.isCurrentJobSuccess()) } }
steps {
script {
deployToArtifactory(common)
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
for (machine in listOfTargets) {
if(isMachineSane(machine)) {
println "BUILDING ${machine}"
runBuildJob(common, machine, "${params.BUILD_BRANCH}")
}
} // end for
} // end catchError
}
}
}
@ -109,72 +97,77 @@ def printJobParameters() {
println "----------------------------------\n\
Job Parameters:\n\
----------------------------------\n\
TARGET = ${params.TARGET}\n\
BUILD_BRANCH = ${params.BUILD_BRANCH}\n\
CLEAN_BUILD = ${params.CLEAN_BUILD}\n\
DEPLOY_TO_NEXUS = ${params.DEPLOY_TO_NEXUS}\n\
DEBUGGING = ${params.DEBUGGING}\n\
BUILD_BRANCH = ${params.BUILD_BRANCH}\n\
CLEAN_BUILD = ${params.CLEAN_BUILD}\n\
DEPLOY_TO_NEXUS = ${params.DEPLOY_TO_NEXUS}\n\
SKIP_SSTATE_UPLOAD = ${params.SKIP_SSTATE_UPLOAD}\n\
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() {
def checkJobParameters(commonHelpers) {
// Check the selected target and overwrite it with a default one when triggered by a timer
def selectedTarget = "${params.TARGET}"
if("${params.TARGET}" == "select...") {
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")
}
if(commonHelpers.isJobTriggeredByTimer()) {
println "INFO: Triggered by Timer"
}
env.TARGET = "${selectedTarget}"
}
//---------------------------------------------------------------------------------------------------------------------
def setDisplayName() {
def setDisplayName(commonHelpers) {
def buildName = "#${env.BUILD_NUMBER}"
def postfix = isJobTriggeredByTimer() ? "-nightly" : ""
def postfix = icommonHelpers.sJobTriggeredByTimer() ? "-nightly" : ""
currentBuild.displayName = "${buildName}-${env.TARGET}${postfix}"
}
//---------------------------------------------------------------------------------------------------------------------
def setupEnvironment(commonHelpers) {
def machine = "${env.TARGET}"
def nwlBranch = "${params.BUILD_BRANCH}"
def nwlRepoDir = "${env.YOCTO_REPO_DIR}"
commonHelpers.setupBuildEnvironment(machine, nwlBranch, nwlRepoDir, params.DEBUGGING)
commonHelpers.printEnvironmentParameters()
commonHelpers.gitCheckout("${env.YOCTO_REPO_URL}", nwlBranch, nwlRepoDir, true)
env.BUILD_IMG_JOB = "/build-target/${env.BRANCH_NAME}"
}
//-----------------------------------------------------------------------------
def getTargetsFromList() {
def theTargets = sh(returnStdout: true, script: "cat ./jobs/nwlTargets | grep -v select").trim().split("\n")
return theTargets
}
//-----------------------------------------------------------------------------
def isMachineSane(machine) {
// ToDo: place here any exclusions if necessary
// adapt the line below as soon as all other target are ready:
return ("${machine}" == "cn9130-cf-pro")
}
//---------------------------------------------------------------------------------------------------------------------
def deployToArtifactory(commonHelpers) {
def artifactFilepath = "${env.DEPLOY_CONTENT_DIR}/${env.ARTIFACT_NAME}"
def nexusGroupId = "nwl.${env.CI_IMAGE}"
def nexusArtifactId = "${env.MACHINE}"
def nexusVersion = "latest"
println "deploying ${artifactFilepath} as ${nexusGroupId}.${nexusArtifactId} to Nexus..."
commonHelpers.deployArtifactToNexusArtifactory(artifactFilepath, "zip", nexusGroupId, nexusArtifactId, nexusVersion)
//-----------------------------------------------------------------------------
def runBuildJob(commonHelpers, buildTarget, buildBranch) {
def buildJob = null
try {
buildJob = build(job: "${env.BUILD_IMG_JOB}",
quietPeriod: 0,
propagate: false,
wait: true,
parameters: [string(name: 'TARGET', value: buildTarget),
string(name: 'BUILD_BRANCH', value: buildBranch),
booleanParam(name: 'CLEAN_BUILD', value: params.CLEAN_BUILD),
booleanParam(name: 'DEPLOY_TO_NEXUS', value: params.DEPLOY_TO_NEXUS),
booleanParam(name: 'SKIP_SSTATE_UPLOAD', value: params.SKIP_SSTATE_UPLOAD),
booleanParam(name: 'DEBUGGING', value: params.DEBUGGING)]
)
}
catch(Exception e) {
println "Exception caught: " + e.toString()
return
}
// assert to be sure
if(buildJob == null) {
error("Something went really wrong with ${env.BUILD_IMG_JOB} (TARGET=${buildTarget})")
return
}
if(buildJob.getResult() != 'SUCCESS') {
currentBuild.result = 'FAILURE'
}
return buildJob
}