From 68cc1dc57d2dccc7253497e0f4098dcd3fa86862 Mon Sep 17 00:00:00 2001 From: Alexandre Bard Date: Fri, 4 Sep 2020 16:39:04 +0200 Subject: [PATCH] Add first jenkinsfile --- Jenkinsfile | 175 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 175 insertions(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..a3a731e --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,175 @@ +// declarative pipeline +pipeline { + agent { + node { + label 'yoctoproject-dunfell' + } + } + + parameters { + choice(name: 'MACHINE_TYPE', choices: ['am335x-nmhw21','imx8-nmhw23'], description: 'choose target platform') + choice(name: 'IMAGE_TYPE', choices: ['bootloader', 'release', 'dev', 'vcu', 'lava', 'sdk'], description: 'choose target platform') + choice(name: 'BUILD_TYPE', choices: ['nightly','release','develop'], description: 'choose the build type') + booleanParam(name: 'CLEAN_BUILD', defaultValue: false, description: 'clean all temp directories before build starts') + } + + environment { + PACKAGE_NAME = 'nm-os' + SLACK_TOKEN = '54fghFEpv1Rmf6GJ4gJ7cL2y' + + MACHINE = "${MACHINE_TYPE}" + + SHARED_BUILD = "${HOME}/yocto-share/build" + ARCHIVER_SOURCES = "${SHARED_BUILD}/tmp/deploy/sources" + build_deploy = "${SHARED_BUILD}/tmp/deploy/images/${machine}" + build_licenses = "${SHARED_BUILD}/tmp/deploy/licenses" + buildhistory = "${HOME}/yocto-share/buildhistory" + } + + options { + timeout(time: 8, unit: 'HOURS') + buildDiscarder(logRotator(numToKeepStr: '5')) + disableConcurrentBuilds() + } + + stages { + stage('prepare') { + steps { + script { + if(params.BUILD_TYPE == 'release') { + sh 'git submodule update' // set all submodules to freezed commit + currentBuild.rawBuild.keepLog(true) // keep this build forever + } + else { + sh 'git submodule update --remote --rebase' // update all submodules to HEAD + } + + version = sh returnStdout: true, script: 'git describe --tags --dirty' + version = version.trim() + + println "----------------------------------\n Job Parameters:\n----------------------------------\n\ + MACHINE_TYPE = ${params.MACHINE_TYPE}\n\ + IMAGE_TYPE = ${params.IMAGE_TYPE}\n\ + BUILD_TYPE = ${params.BUILD_TYPE}\n\ + CLEAN_BUILD = ${params.CLEAN_BUILD}\n\ +----------------------------------\n" + + env.BUILD_VERSION = "${version}" + currentBuild.displayName = "${version}" //replace Bitbake timestamp after building + } + writeFile file: 'VERSION', text: "${PACKAGE_NAME}: ${BUILD_VERSION}" + } + } + + stage('clean') { + when { expression { return params.CLEAN_BUILD } } + steps { + lock("${LOCK_NAME}") { + dir ("${SHARED_BUILD}/tmp") { deleteDir() } + dir ("${SHARED_BUILD}/tmp-glibc") { deleteDir() } + } + } + } + + stage('archive') { + when { environment name: 'BUILD_TYPE', value: 'release' } + steps { + sh "git-archive-all --extra VERSION ${PACKAGE_NAME}-${BUILD_VERSION}-git-archive.tar.gz" + archiveArtifacts artifacts: "${PACKAGE_NAME}-${BUILD_VERSION}-git-archive.tar.gz", onlyIfSuccessful: true + } + post { + success { sh "rm ${PACKAGE_NAME}-${BUILD_VERSION}-git-archive.tar.gz" } + } + } + + stage('build') { + steps { + script { + build_and_deploy() + } + } + } + } // stages + + post { + always { + dir ('tmp') { + deleteDir() + } + dir ("${build_deploy}") { + sh label: 'remove deployment image files', returnStatus: true, script: 'rm netmodule-linux-image-*' + } + } + } +} + + +def build_and_deploy() { + if (params.IMAGE_TYPE == 'sdk') { + sh "bash -c '. ./env.image-ostree && bitbake -k netmodule-linux-image -c populate_sdk'" + zip archive: true, dir: "${HOME}/yocto-share/build/tmp/deploy/sdk", glob: '*.sh', zipFile: "${PACKAGE_NAME}-${BUILD_VERSION}-${machine}-sdk.zip" + } + else if (params.IMAGE_TYPE == 'bootloader') { + sh "bash -c '. ./env.common && bitbake virtual/bootloader'" + } + else if (params.IMAGE_TYPE == 'vcu') { + build('vcu', 'vcu', false) + deploy('vcu', false) + } + else if (params.IMAGE_TYPE == 'lava' || params.IMAGE_TYPE == 'fct' || params.IMAGE_TYPE == 'minimal') { + build(params.IMAGE_TYPE, params.IMAGE_TYPE, true) + deploy(params.IMAGE_TYPE, true) + } + else { + build('ostree', params.IMAGE_TYPE, false) + deploy(params.IMAGE_TYPE, false) + } +} + +def build(env_in, image_type_in, single_fitImage) { + def env = "${env_in}" == "" ? "" : "-${env_in}" + def image_type = "${image_type_in}" == "" ? "" : "-${image_type_in}" + if (single_fitImage) { + sh "bash -c '. ./env.image${env} && bitbake -k virtual/kernel'" + } else { + sh "bash -c '. ./env.image${env} && bitbake -fc cleanall netmodule-linux-image${image_type} && bitbake -k netmodule-linux-image${image_type}'" + } +} + +def deploy(image_type_in, single_fitImage) { + def image_type = "${image_type_in}" == "" ? "" : "-${image_type_in}" + dir ("tmp/build${image_type}") { + def image_basename = "netmodule-linux-image${image_type}-${machine}" + def basename_in = "${build_deploy}/${image_basename}" + def basename_out = "./image${image_type}-${machine}" + + sh "cp ${basename_in}.manifest ${basename_out}.manifest" + sh "bash -c '${WORKSPACE}/scripts/buildhistory-collect-srcrevs -p ${buildhistory} > srcrev-${machine}${image_type}.inc'" + + sh label: 'Copy License Manifest', returnStatus: true, script: """ + LATEST_LICENSE_DIR=\$(ls -Artd ${build_licenses}/netmodule-linux-image${image_type}* | tail -n 1) + cp \$LATEST_LICENSE_DIR/license.manifest ${basename_out}_license.manifest""" + + if (single_fitImage == false) { + sh label: 'Copy initramfs License Manifest', returnStatus: true, script: """ + LATEST_LICENSE_DIR=\$(ls -Artd ${build_licenses}/initramfs-ostree-image-${machine}-* | tail -n 1) + cp \$LATEST_LICENSE_DIR/license.manifest initramfs-ostree-image_license.manifest + """ + } + + if(single_fitImage){ + sh "cp ${build_deploy}/fitImage-${image_basename}-${machine} fitImage-${image_basename}" + sh "cp ${basename_in}.tar.gz ${basename_out}.tar.gz" + } + else { + sh "cp ${build_deploy}/fitImage-${machine}.bin ." + sh "cp ${basename_in}.ota-ext4 ${basename_out}.ota-ext4" + sh "cp ${basename_in}.wic ${basename_out}.wic" + def ostree_archive = "ostree_repo${image_type}.tar.gz" + sh "tar czf ./${ostree_archive} -C ${build_deploy}/ostree_repo ." + sh "rm -rf ${build_deploy}/ostree_repo" + } + } +} + +