// Loading code requires a NODE context // But we want the code accessible outside the node Context // So declare yoctocommon (object created by the LOAD operation) outside the Node block. def yoctocommon // declarative pipeline pipeline { agent { node { label "${params.NODE_NAME}" } } parameters { choice(name: 'MACHINE', choices: ['select...', 'armada-385-nrhw18', 'am335x-nrhw20', 'am335x-nmhw21', 'imx8-nmhw23', 'am335x-nmhw24', 'am335x-hw25', 'am335x-hw26'], description: 'choose target platform') string(name: 'RLS_VERSION', defaultValue: '', description: 'Set the version to build and use committed submodules') string(name: 'NODE_NAME', defaultValue: 'oem-ci', description: 'Enter a specific node name') booleanParam(name: 'CLEAN_BUILD', defaultValue: false, description: 'clean all temp directories before build starts') booleanParam(name: 'BUILD_FROM_DEV_IMAGE', defaultValue: false, description: 'build SDK from dev image') } environment { // SDK Build Parameter (default is recipe netmodule-linux-sdk) IS_NM_LINUX_SDK = "${!params.BUILD_FROM_DEV_IMAGE}" } options { timeout(time: 8, unit: 'HOURS') buildDiscarder( logRotator(numToKeepStr: '6') ) } stages { stage('prepare') { steps { script { if("${params.MACHINE}" == "select...") { currentBuild.result = 'ABORTED' error("Missing machine type --> select parameter MACHINE for a proper build") } // this definition is needed for selecting the // correct build directory env.BUILD_DIR_POSTFIX = "" // take the correct user ID for the ssh connection of // the belonging build server if("${params.NODE_NAME}" == "lxbuild4") { env.SSH_ID = '6b90ac7f-9596-4e43-923b-6c9179a10d8a' } else if("${params.NODE_NAME}" == "lxbuild3") { env.SSH_ID = '70c27394-cb7d-4304-aed1-89e15a3a78d0' } else { error("Declare the NODE_NAME specific to the build agent") } println "SSH_ID used: ${env.SSH_ID}" // load yocto common file env.ROOTDIR = pwd() yoctocommon = load "${env.ROOTDIR}/Jenkinsfile_Common" // clean-up no longer needed packages yoctocommon.cleanWorkspace() // Prepare Build Environment env.YOCTO_DEPLOYS = "${env.SHARED_BUILD}/tmp/deploy/sdk" yoctocommon.handleSubmodules("${params.RLS_VERSION}") yoctocommon.handleAutoRevIncludeFile("${params.RLS_VERSION}") cleanLastBuildArtifacts() version = yoctocommon.getVersionString("${params.RLS_VERSION}", "sdk") env.BUILD_VERSION = "${version}" currentBuild.displayName = "${version}-${params.MACHINE}-sdk" //replace Bitbake timestamp after building printJobParameters() yoctocommon.changeDistroVersion("${version}") yoctocommon.syncSources("${env.BINARY_STORAGE_URL}", "${env.DOWNLOAD_DIR}") } writeFile file: 'VERSION', text: "${env.PACKAGE_NAME}: ${env.BUILD_VERSION}" } } stage('clean') { when { expression { return params.CLEAN_BUILD } } steps { script { cleaning(env.IS_NM_LINUX_SDK.toBoolean()) } } } stage('build') { steps { script { sshagent (credentials: [env.SSH_ID]) { if(env.IS_NM_LINUX_SDK.toBoolean()) { sh "bash -c '. ./env.image-ostree && bitbake -q netmodule-linux-sdk'" } else { sh "bash -c '. ./env.image-ostree && bitbake -q -fc populate_sdk netmodule-linux-image-dev'" } } } } post { success { script{ deploySdkToArtifactory(params.BUILD_FROM_DEV_IMAGE, "${params.MACHINE}") } } // success always { script { yoctocommon.cleanupAutoRevIncludeFile("${params.RLS_VERSION}") yoctocommon.syncSources("${env.DOWNLOAD_DIR}", "${env.BINARY_STORAGE_URL}") } } // always } } } // stages } def printJobParameters() { println "----------------------------------\n\ Job Parameters:\n\ ----------------------------------\n\ MACHINE = ${params.MACHINE}\n\ CLEAN_BUILD = ${params.CLEAN_BUILD}\n\ IS_NM_LINUX_SDK = ${env.IS_NM_LINUX_SDK}\n\ RLS_VERSION = ${params.RLS_VERSION}\n\ --> version = ${env.BUILD_VERSION}\n\ ----------------------------------\n" } def cleanLastBuildArtifacts() { println "cleaning artifacts from last build..." sh "rm -f ${env.YOCTO_DEPLOYS}/*" sshagent (credentials: [env.SSH_ID]) { sh "bash -c '. ./env.image-ostree > /dev/null && git fetch -ap && bitbake -q -c cleanall netmodule-linux-sdk'" } } def cleaning(isNmSdk) { sshagent (credentials: [env.SSH_ID]) { if(env.IS_NM_LINUX_SDK.toBoolean()) { sh "bash -c '. ./env.image-ostree && bitbake -q -fc cleanall netmodule-linux-sdk'" } else { sh "bash -c '. ./env.image-ostree && bitbake -q -fc cleanall netmodule-linux-image-dev'" } } dir ("${env.SHARED_BUILD}/tmp") { deleteDir() } dir ("${env.SHARED_BUILD}/tmp-glibc") { deleteDir() } } def deploySdkToArtifactory(isBuildFromDev, machine) { def cpuType = machine.split("-")[0] def sdkArtifact = sh(returnStdout: true, script: "ls ${env.YOCTO_DEPLOYS}/netmodule-linux-ostree*-netmodule-linux-*.sh").trim() if(isBuildFromDev) { def jenkinsBaseUrl = "https://jenkins.netmodule.intranet" def workspaceUrl = "${jenkinsBaseUrl}/job/NMOS/job/build-sdk/job/${env.BRANCH_NAME}/${currentBuild.number}/execution/node/3/ws/build/tmp/deploy/sdk" def artifactFile = sh(returnStdout: true, script: "basename ${sdkArtifact}") println "Download link of image-sdk (cpuType=${cpuType}): ${workspaceUrl}/${artifactFile}" return } println "Deploying ${sdkArtifact} (cpuType=${cpuType}) to NEXUS..." nexusArtifactUploader( nexusVersion: "nexus3", protocol: "https", nexusUrl: "repo.netmodule.intranet:443", groupId: "nm.sdk", version: "latest", repository: "nm-os", credentialsId: "0099cd5a-81d4-4698-9b55-1206895d19fb", artifacts: [ [artifactId: "${cpuType}", classifier: "", file: "${sdkArtifact}", type: "sh"] ] ); }