yocto-img-build/Jenkinsfile_mmcImages

171 lines
6.0 KiB
Plaintext

// 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 'oem-ci'
}
}
parameters {
choice(name: 'MACHINE', choices: ['select...', 'am335x-nrhw20', 'am335x-nmhw21', 'imx8-nmhw23', 'am335x-nmhw24', 'am335x-hw25', 'am335x-hw26'], description: 'choose target platform')
choice(name: 'IMAGE_TYPE', choices: ['dev', 'bootloader', 'release'], description: 'choose image type')
string(name: 'RLS_VERSION', defaultValue: '', description: 'Set the version to build and use committed submodules')
booleanParam(name: 'CLEAN_BUILD', defaultValue: false, description: 'clean all temp directories before build starts')
}
environment {
IMG_OUTPUT_DIR = "tmp/build-output"
}
options {
timeout(time: 5, unit: 'HOURS')
buildDiscarder(
logRotator(numToKeepStr: '50',
daysToKeepStr: '3',
artifactNumToKeepStr: '50',
artifactDaysToKeepStr: '3'
)
)
disableConcurrentBuilds()
}
stages {
stage('prepare') {
steps {
script {
if("${params.MACHINE}" == "select...") {
currentBuild.result = 'ABORTED'
error("Missing machine type --> select parameter MACHINE for a proper build")
}
// load yocto common file
env.ROOTDIR = pwd()
yoctocommon = load "${env.ROOTDIR}/Jenkinsfile_Common"
// Prepare Build Environment
env.YOCTO_DEPLOYS = "${env.BUILD_DEPLOY_DIR}/${params.MACHINE}"
yoctocommon.handleSubmodules("${params.RLS_VERSION}")
version = yoctocommon.getVersionString("${params.RLS_VERSION}", "${params.IMAGE_TYPE}")
env.BUILD_VERSION = "${version}"
currentBuild.displayName = "${version}-${params.MACHINE}-${params.IMAGE_TYPE}" //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 {
dir ("${SHARED_BUILD}/tmp") { deleteDir() }
dir ("${SHARED_BUILD}/tmp-glibc") { deleteDir() }
}
}
stage('build') {
steps {
script {
build(params.IMAGE_TYPE)
createArchive(params.IMAGE_TYPE, env.IMG_OUTPUT_DIR)
if(params.IMAGE_TYPE != 'bootloader') {
archiveOSTreeArtifact(env.IMG_OUTPUT_DIR)
}
yoctocommon.archiveImages(env.IMG_OUTPUT_DIR)
}
}
post {
always {
script {
yoctocommon.syncSources("${env.DOWNLOAD_DIR}", "${env.BINARY_STORAGE_URL}")
}
}
}
}
stage('collect versions') {
steps {
script {
revisions = yoctocommon.getAutoRevHashes('ostree')
writeFile(file: "${env.AUTOREV_VERSION_FILE}", text: "${revisions}")
}
}
post {
success {
archiveArtifacts(artifacts: "${env.SUBMODULE_VERION_FILE}, ${env.AUTOREV_VERSION_FILE}, ${env.DISTRO_VERSION_FILE}", onlyIfSuccessful: false)
}
}
}
} // stages
}
def printJobParameters() {
println "----------------------------------\n\
Job Parameters:\n\
----------------------------------\n\
MACHINE = ${params.MACHINE}\n\
IMAGE_TYPE = ${params.IMAGE_TYPE}\n\
CLEAN_BUILD = ${params.CLEAN_BUILD}\n\
RLS_VERSION = ${params.RLS_VERSION}\n\
--> version = ${env.BUILD_VERSION}\n\
----------------------------------\n"
}
def build(imgType) {
if(imgType == 'bootloader') {
sh "bash -c '. ./env.image-ostree && bitbake virtual/bootloader'"
return
}
def imgTypePostfix = "${imgType}" == "" ? "" : "-${imgType}"
sh "bash -c '. ./env.image-ostree && bitbake -k netmodule-linux-image${imgTypePostfix}'"
}
def createArchive(imgType, outputDir) {
dir (outputDir) {
if(imgType == 'bootloader') {
sh "cp ${env.YOCTO_DEPLOYS}/*u-boot-${params.MACHINE}*.img . || true"
sh "cp ${env.YOCTO_DEPLOYS}/*u-boot-${params.MACHINE}*.xmodem.bin . || true"
sh "cp ${env.YOCTO_DEPLOYS}/imx-boot . || true"
sh "cp ${env.YOCTO_DEPLOYS}/imx-boot.sd . || true"
return
}
def imgTypePostfix = "${imgType}" == "" ? "" : "-${imgType}"
def image_basename = "netmodule-linux-image${imgTypePostfix}-${params.MACHINE}"
def basename_built = "${env.YOCTO_DEPLOYS}/${image_basename}"
def basename_archive = "./image${imgTypePostfix}-${params.MACHINE}"
sh "cp ${basename_built}.manifest ${basename_archive}.manifest"
sh "bash -c '${WORKSPACE}/openembedded-core/scripts/buildhistory-collect-srcrevs -p ${env.BUILD_HISTORY_DIR} > srcrev-${params.MACHINE}${imgTypePostfix}.inc'"
sh label: 'Copy License Manifest', returnStatus: true, script: """
LATEST_LICENSE_DIR=\$(ls -Artd ${env.BUILD_LICENSE_DIR}/netmodule-linux-image${imgTypePostfix}* | tail -n 1)
cp \$LATEST_LICENSE_DIR/license.manifest ${basename_archive}_license.manifest
"""
sh label: 'Copy initramfs License Manifest', returnStatus: true, script: """
LATEST_LICENSE_DIR=\$(ls -Artd ${env.BUILD_LICENSE_DIR}/initramfs-ostree-image-${params.MACHINE}-* | tail -n 1)
cp \$LATEST_LICENSE_DIR/license.manifest initramfs-ostree-image_license.manifest
"""
sh "cp ${env.YOCTO_DEPLOYS}/fitImage-${params.MACHINE}.bin ."
sh "cp ${basename_built}.ota-ext4 ${basename_archive}.ota-ext4"
sh "cp ${basename_built}.wic ${basename_archive}.wic"
sh "tar czf ./ostree_repo${imgTypePostfix}.tar.gz -C ${env.YOCTO_DEPLOYS}/ostree_repo ."
}
}
def archiveOSTreeArtifact(outputDir) {
archiveArtifacts artifacts: "${outputDir}/ostree_repo*.tar.gz", onlyIfSuccessful: true
sh "rm -f ./${outputDir}/ostree_repo*.tar.gz"
}