// declarative pipeline pipeline { agent { node { label 'lxbuild4' } } parameters { booleanParam(name: 'UPDATE_NM_PARTS', defaultValue: true, description: 'update the netmodule submodules (e.g. before releasing)') booleanParam(name: 'UPDATE_COMMUNITY_PARTS', defaultValue: false, description: 'update the the community submodules (maintenance/security updates)') } environment { SUBMODULE_VERSION_FILE = "submodule_revisions" SOURCE_REVISION_UPDATE_LOG = "src_rev_update.log" SSH_ID = '6b90ac7f-9596-4e43-923b-6c9179a10d8a' } options { timeout(time: 1, unit: 'HOURS') buildDiscarder( logRotator(numToKeepStr: '5') ) disableConcurrentBuilds() } stages { stage('prepare') { steps { script { if(params.UPDATE_NM_PARTS) { currentBuild.displayName += "-nm" } if(params.UPDATE_COMMUNITY_PARTS) { currentBuild.displayName += "-community" } printJobParameters() prepareUpdate() } } } stage('update to head') { steps { script { updateSubmodules(params.UPDATE_NM_PARTS, params.UPDATE_COMMUNITY_PARTS) updateSourceRevisions(params.UPDATE_NM_PARTS) } } post { success { archiveArtifacts(artifacts: "${env.SUBMODULE_VERSION_FILE}", onlyIfSuccessful: false) sh "rm -f ${env.SUBMODULE_VERSION_FILE}" } } } stage('commit') { steps { commitChanges(params.UPDATE_NM_PARTS, params.UPDATE_COMMUNITY_PARTS) } } } // stages } def printJobParameters() { def node_name = "${NODE_NAME}" println "Running on agent: ${node_name}\n\n" println "----------------------------------\n\ Job Parameters:\n\ ----------------------------------\n\ UPDATE_NM_PARTS = ${params.UPDATE_NM_PARTS}\n\ UPDATE_COMMUNITY_PARTS = ${params.UPDATE_COMMUNITY_PARTS}\n\ ----------------------------------\n" } def prepareUpdate() { sshagent (credentials: [env.SSH_ID]) { sh 'git submodule update --init' // init submodules used if first checkout } def userId = "${currentBuild.getBuildCauses()[0].userId}" def userName = "${currentBuild.getBuildCauses()[0].userName}" if("${userId}" == "null") { userId = "downstream" userName = "Jenkins" } env.TRIGGERED_USER = "${userName} (userId=${userId})" def notNmUpdate = "${!params.UPDATE_NM_PARTS}" def notCommunityUpdate = "${!params.UPDATE_COMMUNITY_PARTS}" if(notNmUpdate.toBoolean() && notCommunityUpdate.toBoolean()) { error("Nothing to update selected - both parameters are false") } } def updateSubmodules(isNmUpdate, isCommunityUpdate) { sshagent (credentials: [env.SSH_ID]) { if(isNmUpdate) { sh(script: "git submodule update --remote --rebase meta-netmodule-*") } if(isCommunityUpdate) { sh(script: "git submodule update --remote --rebase \$(git submodule status | grep -v \"meta-netmodule-*\" | sed 's/^ *//g' | cut -d' ' -f2)") } } submoduleStatus = sh(returnStdout: true, script: "git submodule status").trim() // print submodule hashes to jenkins log println "${submoduleStatus}" writeFile(file: "${env.SUBMODULE_VERSION_FILE}", text: "${submoduleStatus}") } def updateMachineSrcRevs(machine) { // set the reference machine to be able to load the yocto environment (used for devtool) env.MACHINE = "${machine}" println "update source revisions for ${env.MACHINE} to head..." sh("echo '==> ${env.MACHINE} =======================' >> ./${env.SOURCE_REVISION_UPDATE_LOG}") sh(returnStdout: true, script: "bash -c '. ./env.image-ostree > /dev/null && cd ../ && ./src-rev.sh -v -d -r -l ./srcrev.log -a ./autorev-packages.inc'") sh("cat ./srcrev.log >> ./${env.SOURCE_REVISION_UPDATE_LOG}") } def updateSourceRevisions(isNmUpdate) { if(!isNmUpdate) { // Netmodule layers are not called to update --> returning return } sh("echo '================== UPDATE SOURCE REVISIONS ==================' > ./${env.SOURCE_REVISION_UPDATE_LOG}") updateMachineSrcRevs("am335x-hw26") updateMachineSrcRevs("imx8-nmhw23") sh(returnStdout: true, script: "git checkout build/conf/bblayers.conf") } def commitSourceRevisionChanges() { println "commit source revision changes..." sshagent (credentials: [env.SSH_ID]) { sh(returnStdout: true, script: "./src-rev-commit.sh -b develop -v -l ./srcrev-commit.log") } sh "cat ./srcrev-commit.log >> ./${env.SOURCE_REVISION_UPDATE_LOG}" } def commitChanges(isNmUpdate, isCommunityUpdate) { String updatedLayers = "" if(isNmUpdate) { commitSourceRevisionChanges() updatedLayers += "netmodule" } if(isNmUpdate && isCommunityUpdate) { updatedLayers += " and " } if(isCommunityUpdate) { updatedLayers += "community" } sh(script: "git checkout ${env.BRANCH_NAME}") sh(script: "git add -u") stagedData = sh(returnStdout: true, script: "git diff --cached").trim() if("${stagedData}" == "") { println "everything up to date, nothing to commit" return } sshagent (credentials: [env.SSH_ID]) { sh(script: "git commit -m \"submodules: updated ${updatedLayers} hashes, triggered by ${env.TRIGGERED_USER}\" && git push") } }