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 { parameters {
string(name: 'BUILD_BRANCH', defaultValue: 'main', description: 'Enter the branch of the NWL to build (default = main), will skip deployment if not main') 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: '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: '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') 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 { triggers {
cron('H H(5-6) * * 1-5') cron('H H(5-6) * * 1-5')
} }
@ -67,7 +69,15 @@ pipeline {
println "CLEAN BUILD REQUESTED, cleaning..." println "CLEAN BUILD REQUESTED, cleaning..."
common.cleaningClonedRepoDir() 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') { stage('Build All Targets') {
steps { steps {
script { script {
buildAllTargets(common, "${params.BUILD_BRANCH}") buildAllTargets(common, "${env.BRANCH_TO_BUILD}")
} }
} }
} }
@ -95,7 +105,6 @@ def printJobParameters() {
DEBUGGING = ${params.DEBUGGING}\n\ DEBUGGING = ${params.DEBUGGING}\n\
----------------------------------\n" ----------------------------------\n"
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
def checkJobParameters(commonHelpers) { def checkJobParameters(commonHelpers) {
// Check the selected target and overwrite it with a default one when triggered by a timer // 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 setupEnvironment(commonHelpers, selectedBranch) {
def nwlBranch = "${params.BUILD_BRANCH}" env.BUILD_JOB = "${env.TARGET_BUILD_JOB}"
def nwlRepoDir = "${env.YOCTO_REPO_DIR}" env.SRCREV_JOB = "${env.SRCREV_UPDATE_JOB}"
commonHelpers.gitCheckout("${env.YOCTO_REPO_URL}", nwlBranch, nwlRepoDir, true) env.BRANCH_TO_BUILD = "${selectedBranch}"
env.BUILD_IMG_JOB = "/nwl-target"
} }
//-----------------------------------------------------------------------------
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 getTargetsFromList() {
def theTargets = sh(returnStdout: true, script: "set +x && cat ./jobs/nwlTargets | grep -v select").trim().split("\n") 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 // ToDo: place here any exclusions if necessary
return true return true
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
def runBuildJob(commonHelpers, buildTarget, buildBranch) { def runBuildJob(commonHelpers, buildTarget, buildBranch) {
def buildJob = null def buildJob = null
Boolean isSuccessfullyBuilt = true Boolean isSuccessfullyBuilt = true
try { try {
buildJob = build(job: "${env.BUILD_IMG_JOB}", buildJob = build(job: "${env.BUILD_JOB}",
quietPeriod: 0, quietPeriod: 0,
propagate: true, propagate: true,
wait: true, wait: true,
@ -149,12 +196,12 @@ def runBuildJob(commonHelpers, buildTarget, buildBranch) {
) )
} }
catch(Exception e) { catch(Exception e) {
println "Exception caught: " + e.toString() error("Exception: " + e.toString())
return return
} }
// assert to be sure // assert to be sure
if(buildJob == null) { 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 return
} }
isSuccessfullyBuilt = (buildJob.getResult() == 'SUCCESS') isSuccessfullyBuilt = (buildJob.getResult() == 'SUCCESS')