yocto-img-build/Jenkinsfile_sdk

158 lines
5.3 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 "${params.NODE_NAME}"
}
}
parameters {
choice(name: 'MACHINE', choices: ['select...', '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: 5, unit: 'HOURS')
buildDiscarder(
logRotator(numToKeepStr: '5')
)
}
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 = ""
// 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 {
dir ("${SHARED_BUILD}/tmp") { deleteDir() }
dir ("${SHARED_BUILD}/tmp-glibc") { deleteDir() }
}
}
stage('build') {
steps {
script {
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}/*"
sh "bash -c 'git fetch -ap'"
sh "bash -c '. ./env.image-ostree > /dev/null && bitbake -q -c cleanall netmodule-linux-sdk'"
}
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"]
]
);
}