188 lines
6.0 KiB
Plaintext
188 lines
6.0 KiB
Plaintext
// common parts for yocto builds
|
|
|
|
// BUILD_DIR_POSTFIX needs to be defined in the job before
|
|
// loading this module
|
|
env.SHARED_BUILD = "${WORKSPACE}/build${env.BUILD_DIR_POSTFIX}"
|
|
env.BUILD_DEPLOY_DIR = "${env.SHARED_BUILD}/tmp/deploy/images"
|
|
env.BUILD_LICENSE_DIR = "${env.SHARED_BUILD}/tmp/deploy/licenses"
|
|
env.BUILD_HISTORY_DIR = "${env.SHARED_BUILD}/buildhistory"
|
|
env.DISTRO_VERSION_PATHNAME = "${env.SHARED_BUILD}/conf/distro_version.inc"
|
|
env.DOWNLOAD_DIR = "${WORKSPACE}/build-common/downloads"
|
|
env.BINARY_STORAGE_URL = "http://nmrepo.netmodule.intranet/src/yocto-downloads"
|
|
env.SUBMODULE_VERION_FILE = "submodule_revisions"
|
|
env.DISTRO_VERSION_FILE = "distro_version.inc"
|
|
env.AUTOREV_VERSION_FILE = "autorev_revisions.inc"
|
|
env.PACKAGE_NAME = "nm-os"
|
|
|
|
|
|
echo "loading common yocto build module..."
|
|
|
|
|
|
// Methods declared in external code are accessible
|
|
// directly from other code in the external file
|
|
// indirectly via the object created by the load operation
|
|
// eg. extcode.build(...)
|
|
|
|
|
|
def cleanWorkspace() {
|
|
println "cleaning workspace..."
|
|
sh "[ -d \"${WORKSPACE}/build-common/sstate-cache\" ] && find \"${WORKSPACE}/build-common/sstate-cache/\" -name \"sstate*\" -atime +3 -delete || true"
|
|
sh "[ -d \"${env.SHARED_BUILD}/tmp/work\" ] && find \"${env.SHARED_BUILD}/tmp/work/\" -name temp -type d -exec rm -rf {} + || true"
|
|
}
|
|
|
|
|
|
def isRelease(versionParam) {
|
|
if((versionParam == "") || (versionParam == "latest")) {
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
|
|
|
|
def handleSubmodules(versionParam) {
|
|
println "init submodules..."
|
|
sh 'git submodule update --init'
|
|
if(isRelease(versionParam)) {
|
|
println "set submodules to freezed state..."
|
|
sh 'git submodule update' // set all submodules to freezed commit
|
|
}
|
|
else {
|
|
println "setting netmodule submodule hashes to head..."
|
|
sh 'git submodule update --remote --rebase meta-netmodule-*' // update our own submodules to HEAD
|
|
}
|
|
submoduleStatus = sh(returnStdout: true, script: "git submodule status").trim() // print submodule hashes to jenkins log
|
|
println "${submoduleStatus}"
|
|
writeFile(file: "${env.SUBMODULE_VERION_FILE}", text: "${submoduleStatus}")
|
|
}
|
|
|
|
def handleAutoRevIncludeFile(versionParam) {
|
|
if(isRelease(versionParam)) {
|
|
println "suppressing autorev include file..."
|
|
sh(script: "sed '/autorev-packages/d' -i ${env.SHARED_BUILD}/conf/local.conf")
|
|
}
|
|
}
|
|
def cleanupAutoRevIncludeFile(versionParam) {
|
|
if(isRelease(versionParam)) {
|
|
println "clean-up suppressed autorev include file..."
|
|
sh(script: "git checkout ${env.SHARED_BUILD}/conf/local.conf")
|
|
}
|
|
}
|
|
|
|
def updateSourceRevisions() {
|
|
println "update source revisions to head..."
|
|
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'")
|
|
}
|
|
|
|
|
|
def getTopUpstreamBuildNumber() {
|
|
// Iterating though all upstream jobs:
|
|
// currentBuild.upstreamBuilds.each { item ->
|
|
// echo "upstream build: ${item}"
|
|
// def nbr = item.getNumber()
|
|
// echo "nbr=${nbr}"
|
|
// }
|
|
def upstreamJobList = currentBuild.upstreamBuilds
|
|
def nbrOfUpstreamJobs = upstreamJobList.size()
|
|
if (nbrOfUpstreamJobs == 0)
|
|
return 0;
|
|
def topJob = upstreamJobList[nbrOfUpstreamJobs-1]
|
|
println "Top upstream project: " + topJob.getFullDisplayName()
|
|
def topJobNbr = topJob.getNumber()
|
|
println "Top upstream job build Number = ${topJobNbr}"
|
|
return topJobNbr
|
|
}
|
|
|
|
def buildVersionString(imageType, actualBaseVersionString, versionParameter) {
|
|
// official release version
|
|
if(isRelease(versionParameter)) {
|
|
String newVersionStr = versionParameter
|
|
return newVersionStr
|
|
}
|
|
|
|
// SDK or FCT release
|
|
if((imageType == 'fct') || (imageType == 'sdk')) {
|
|
return actualBaseVersionString
|
|
}
|
|
|
|
// nightly/incremental release
|
|
def buildnbr = getTopUpstreamBuildNumber()
|
|
String nightlyPart = actualBaseVersionString + ".Test${buildnbr}"
|
|
return nightlyPart
|
|
}
|
|
|
|
def getVersionString(versionParam, imageType) {
|
|
sh 'git fetch -ap'
|
|
sh 'git fetch -t'
|
|
def gitCmd = "git describe --tags"
|
|
|
|
if(!isRelease(versionParam)) {
|
|
gitCmd = "${gitCmd} --dirty"
|
|
}
|
|
gitversion = sh(returnStdout: true, script: "${gitCmd}").trim()
|
|
String[] versionArr = "${gitversion}".split("-")
|
|
|
|
versionArr[0] = buildVersionString(imageType, versionArr[0], versionParam)
|
|
rlsVersion = versionArr.join("-")
|
|
return rlsVersion
|
|
}
|
|
|
|
|
|
def changeDistroVersion(versionString){
|
|
println "Set the distro version to ${versionString}..."
|
|
def versionTag = "DISTRO_VERSION = \"${versionString}\""
|
|
writeFile(file: "${env.DISTRO_VERSION_PATHNAME}", text: "${versionTag}")
|
|
sh(script: "cp ${env.DISTRO_VERSION_PATHNAME} ${env.DISTRO_VERSION_FILE}")
|
|
}
|
|
|
|
def cleanupDistroVersion() {
|
|
println "cleaning repository regarding distro version..."
|
|
sh(script:"git clean -f ${env.DISTRO_VERSION_PATHNAME}")
|
|
}
|
|
|
|
|
|
def archiveImages(imgageDir, imgType) {
|
|
dir ('tmp/artifacts') {
|
|
zip archive: true, dir: "${WORKSPACE}/${imgageDir}", glob: "*", zipFile: "${env.PACKAGE_NAME}-${env.BUILD_VERSION}-${params.MACHINE}-${imgType}.zip"
|
|
}
|
|
sh "rm -rf ${WORKSPACE}/tmp/artifacts"
|
|
}
|
|
|
|
|
|
def syncSources(src, dst) {
|
|
def hasSrcUrl = (src.contains("http"))
|
|
def from = src
|
|
def to = dst
|
|
|
|
// convert the URL into ssh syntax:
|
|
def url = (hasSrcUrl) ? src : dst
|
|
String[] repoParts = url.split("//")[1].split("/")
|
|
repoParts[0] = "build_user@" + repoParts[0] + ":/repo/repo"
|
|
sshSrc = repoParts.join("/")
|
|
|
|
if(hasSrcUrl) {
|
|
println "getting data from server..."
|
|
from = sshSrc
|
|
sh(script: "bash -c \"mkdir -p ${to}\"")
|
|
}
|
|
else {
|
|
println "putting data to server..."
|
|
to = sshSrc
|
|
}
|
|
|
|
sshagent (credentials: ['7767e711-08a4-4c71-b080-197253dd7392']) {
|
|
sh "set +x && rsync -q -auvz --ignore-existing -e \"ssh\" ${from}/* ${to}"
|
|
}
|
|
}
|
|
|
|
|
|
def getAutoRevHashes(envType) {
|
|
def env = "${envType}" == "" ? "" : "-${envType}"
|
|
def revs = sh(returnStdout: true, script: "bash -c \". ./env.image${env} > /dev/null && buildhistory-collect-srcrevs\"").trim()
|
|
return revs
|
|
}
|
|
|
|
|
|
// !!Important Boilerplate!!
|
|
// The external code must return it's contents as an object
|
|
return this;
|