jobs/buildAll: build clean per default, added stage updating src rev

the update source revision job is important for a successful nightly
build- Thus the nightly job triggers this job and uses the returned
branch for the build target job.
With this we are able to pass the nightly without already merge a
pull request for new source revisions.

Signed-off-by: Marc Mattmüller <marc.mattmueller@netmodule.com>
This commit is contained in:
Marc Mattmüller 2023-09-11 10:45:20 +02:00
parent c8b22f8cf5
commit b40c884da2
1 changed files with 61 additions and 14 deletions

View File

@ -30,7 +30,7 @@ pipeline {
parameters {
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: 'CLEAN_BUILD', defaultValue: true, 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')
@ -44,6 +44,8 @@ pipeline {
)
}
// ToDo: Remove this statement unless necessary, The cron trigger is set on
// the job configuration and should be sufficient - untested.
triggers {
cron('H H(5-6) * * 1-5')
}
@ -67,7 +69,15 @@ pipeline {
println "CLEAN BUILD REQUESTED, cleaning..."
common.cleaningClonedRepoDir()
}
setupEnvironment(common)
setupEnvironment(common, "${params.BUILD_BRANCH}")
}
}
}
stage('Update Source Revisions') {
steps {
script {
updateTheSourceRevisions(common, "${env.BRANCH_TO_BUILD}")
}
}
}
@ -75,7 +85,7 @@ pipeline {
stage('Build All Targets') {
steps {
script {
buildAllTargets(common, "${params.BUILD_BRANCH}")
buildAllTargets(common, "${env.BRANCH_TO_BUILD}")
}
}
}
@ -95,7 +105,6 @@ def printJobParameters() {
DEBUGGING = ${params.DEBUGGING}\n\
----------------------------------\n"
}
//---------------------------------------------------------------------------------------------------------------------
def checkJobParameters(commonHelpers) {
// Check the selected target and overwrite it with a default one when triggered by a timer
@ -112,13 +121,53 @@ def setDisplayName(commonHelpers) {
//---------------------------------------------------------------------------------------------------------------------
def setupEnvironment(commonHelpers) {
def nwlBranch = "${params.BUILD_BRANCH}"
def nwlRepoDir = "${env.YOCTO_REPO_DIR}"
commonHelpers.gitCheckout("${env.YOCTO_REPO_URL}", nwlBranch, nwlRepoDir, true)
env.BUILD_IMG_JOB = "/nwl-target"
def setupEnvironment(commonHelpers, selectedBranch) {
env.BUILD_JOB = "${env.TARGET_BUILD_JOB}"
env.SRCREV_JOB = "${env.SRCREV_UPDATE_JOB}"
env.BRANCH_TO_BUILD = "${selectedBranch}"
}
//-----------------------------------------------------------------------------
def runUpdateSrcRevJob(commonHelpers, buildBranch, isCleanRequested, isDryRun) {
def updateJob = null
try {
updateJob = build(job: "${env.SRCREV_JOB}",
quietPeriod: 0,
propagate: true,
wait: true,
parameters: [string(name: 'BUILD_BRANCH', value: buildBranch),
booleanParam(name: 'CLEAN_BUILD', value: isCleanRequested),
booleanParam(name: 'DRY_RUN', value: isDryRun)]
)
}
catch(Exception e) {
error("Exception: " + e.toString())
return
}
// assert to be sure
if(updateJob == null) {
error("Something went really wrong with ${env.SRCREV_JOB}")
}
if(updateJob.getResult() != 'SUCCESS') {
error("Failed to update the source revisions, check the job")
}
}
//-----------------------------------------------------------------------------
def updateTheSourceRevisions(commonHelpers, buildBranch) {
def branchToBuild = buildBranch
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
runUpdateSrcRevJob(commonHelpers, buildBranch, true, false)
copyArtifacts(projectName: "${env.SRCREV_JOB}", target: ".", flatten: true)
branchToBuild = sh(returnStdout: true, script: "cat ./${env.NIGHTLY_BRANCH_FILE}").trim()
} // end catchError
// update the branch to build if the source revisions are updated
env.BRANCH_TO_BUILD = "${branchToBuild}"
}
//-----------------------------------------------------------------------------
def getTargetsFromList() {
def theTargets = sh(returnStdout: true, script: "set +x && cat ./jobs/nwlTargets | grep -v select").trim().split("\n")
@ -129,14 +178,12 @@ def isMachineSane(machine) {
// ToDo: place here any exclusions if necessary
return true
}
//-----------------------------------------------------------------------------
def runBuildJob(commonHelpers, buildTarget, buildBranch) {
def buildJob = null
Boolean isSuccessfullyBuilt = true
try {
buildJob = build(job: "${env.BUILD_IMG_JOB}",
buildJob = build(job: "${env.BUILD_JOB}",
quietPeriod: 0,
propagate: true,
wait: true,
@ -149,12 +196,12 @@ def runBuildJob(commonHelpers, buildTarget, buildBranch) {
)
}
catch(Exception e) {
println "Exception caught: " + e.toString()
error("Exception: " + e.toString())
return
}
// assert to be sure
if(buildJob == null) {
error("Something went really wrong with ${env.BUILD_IMG_JOB} (TARGET=${buildTarget})")
error("Something went really wrong with ${env.BUILD_JOB} (TARGET=${buildTarget})")
return
}
isSuccessfullyBuilt = (buildJob.getResult() == 'SUCCESS')