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:
parent
cd76fd0385
commit
850e9f746e
|
|
@ -3,9 +3,6 @@
|
||||||
// So declare common (object created by the LOAD operation) outside the Node block.
|
// So declare common (object created by the LOAD operation) outside the Node block.
|
||||||
def common
|
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
|
// 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
|
// 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
|
// 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 ."
|
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
|
// load common file
|
||||||
common = load "./jobs/Jenkinsfile_Common"
|
common = load "./jobs/Jenkinsfile_Common"
|
||||||
}
|
}
|
||||||
|
|
@ -35,10 +29,10 @@ pipeline {
|
||||||
agent any
|
agent any
|
||||||
|
|
||||||
parameters {
|
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')
|
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: 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: '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')
|
booleanParam(name: 'DEBUGGING', defaultValue: false, description: 'debugging mode, removes quiet mode for bitbake')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -60,8 +54,8 @@ pipeline {
|
||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
printJobParameters()
|
printJobParameters()
|
||||||
checkJobParameters()
|
checkJobParameters(common)
|
||||||
setDisplayName()
|
setDisplayName(common)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -81,22 +75,16 @@ pipeline {
|
||||||
stage('Build') {
|
stage('Build') {
|
||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
dir("${env.YOCTO_REPO_DIR}") {
|
def listOfTargets = getTargetsFromList()
|
||||||
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"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stage('Deploy') {
|
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
|
||||||
when { expression { return (params.DEPLOY_TO_NEXUS && common.isCurrentJobSuccess()) } }
|
for (machine in listOfTargets) {
|
||||||
steps {
|
if(isMachineSane(machine)) {
|
||||||
script {
|
println "BUILDING ${machine}"
|
||||||
deployToArtifactory(common)
|
runBuildJob(common, machine, "${params.BUILD_BRANCH}")
|
||||||
|
}
|
||||||
|
} // end for
|
||||||
|
} // end catchError
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -109,72 +97,77 @@ def printJobParameters() {
|
||||||
println "----------------------------------\n\
|
println "----------------------------------\n\
|
||||||
Job Parameters:\n\
|
Job Parameters:\n\
|
||||||
----------------------------------\n\
|
----------------------------------\n\
|
||||||
TARGET = ${params.TARGET}\n\
|
BUILD_BRANCH = ${params.BUILD_BRANCH}\n\
|
||||||
BUILD_BRANCH = ${params.BUILD_BRANCH}\n\
|
CLEAN_BUILD = ${params.CLEAN_BUILD}\n\
|
||||||
CLEAN_BUILD = ${params.CLEAN_BUILD}\n\
|
DEPLOY_TO_NEXUS = ${params.DEPLOY_TO_NEXUS}\n\
|
||||||
DEPLOY_TO_NEXUS = ${params.DEPLOY_TO_NEXUS}\n\
|
SKIP_SSTATE_UPLOAD = ${params.SKIP_SSTATE_UPLOAD}\n\
|
||||||
DEBUGGING = ${params.DEBUGGING}\n\
|
DEBUGGING = ${params.DEBUGGING}\n\
|
||||||
----------------------------------\n"
|
----------------------------------\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
def isJobTriggeredByTimer() {
|
def checkJobParameters(commonHelpers) {
|
||||||
// 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() {
|
|
||||||
// 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
|
||||||
def selectedTarget = "${params.TARGET}"
|
if(commonHelpers.isJobTriggeredByTimer()) {
|
||||||
if("${params.TARGET}" == "select...") {
|
println "INFO: Triggered by Timer"
|
||||||
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 setDisplayName(commonHelpers) {
|
||||||
def buildName = "#${env.BUILD_NUMBER}"
|
def buildName = "#${env.BUILD_NUMBER}"
|
||||||
def postfix = isJobTriggeredByTimer() ? "-nightly" : ""
|
def postfix = icommonHelpers.sJobTriggeredByTimer() ? "-nightly" : ""
|
||||||
currentBuild.displayName = "${buildName}-${env.TARGET}${postfix}"
|
currentBuild.displayName = "${buildName}-${env.TARGET}${postfix}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
def setupEnvironment(commonHelpers) {
|
def setupEnvironment(commonHelpers) {
|
||||||
def machine = "${env.TARGET}"
|
|
||||||
def nwlBranch = "${params.BUILD_BRANCH}"
|
def nwlBranch = "${params.BUILD_BRANCH}"
|
||||||
def nwlRepoDir = "${env.YOCTO_REPO_DIR}"
|
def nwlRepoDir = "${env.YOCTO_REPO_DIR}"
|
||||||
commonHelpers.setupBuildEnvironment(machine, nwlBranch, nwlRepoDir, params.DEBUGGING)
|
commonHelpers.gitCheckout("${env.YOCTO_REPO_URL}", nwlBranch, nwlRepoDir, true)
|
||||||
commonHelpers.printEnvironmentParameters()
|
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 runBuildJob(commonHelpers, buildTarget, buildBranch) {
|
||||||
def artifactFilepath = "${env.DEPLOY_CONTENT_DIR}/${env.ARTIFACT_NAME}"
|
def buildJob = null
|
||||||
def nexusGroupId = "nwl.${env.CI_IMAGE}"
|
try {
|
||||||
def nexusArtifactId = "${env.MACHINE}"
|
buildJob = build(job: "${env.BUILD_IMG_JOB}",
|
||||||
def nexusVersion = "latest"
|
quietPeriod: 0,
|
||||||
|
propagate: false,
|
||||||
println "deploying ${artifactFilepath} as ${nexusGroupId}.${nexusArtifactId} to Nexus..."
|
wait: true,
|
||||||
commonHelpers.deployArtifactToNexusArtifactory(artifactFilepath, "zip", nexusGroupId, nexusArtifactId, nexusVersion)
|
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
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue