blob: c65a656feef9307dbd785da7842f608af8685533 [file] [log] [blame]
#!/usr/bin/env groovy
library 'functions'
def boardName = params.boardName
def releaseName = params.releaseName
def workspacePath = "/home/jenkins/workspace"
def buildLabel = "image.${releaseName}.${boardName}-${UUID.randomUUID().toString()}"
def sourcePath = "${workspacePath}/src"
// FIXME(jtgans): Get rid of privileged! This is a security risk!
def jnlpContainer = containerTemplate(name: 'jnlp',
image: 'jenkins/jnlp-slave:alpine')
def debianContainer = containerTemplate(name: 'debian',
image: 'gcr.io/mendel-linux-cloud-infra/mendel-builder:latest',
command: 'cat',
args: '',
ttyEnabled: true,
privileged: true)
def aptlyVolume = persistentVolumeClaim(claimName: 'aptly-state', mountPath: '/var/lib/aptly')
podTemplate(label: buildLabel, containers: [jnlpContainer, debianContainer], volumes: [aptlyVolume], envVars: []) {
node(buildLabel) {
dir(sourcePath) {
container('debian') {
def envVars = [
'IS_JENKINS=true',
"RELEASE_NAME=${releaseName}",
'USER=root'
]
withEnv(envVars) {
stage('Init') {
functions.initSourceTree(boardName, false /* needsNative */)
}
stage('Build') {
def nprocs = sh(returnStdout: true, script: 'nproc').trim()
sh "bash -c 'source build/setup.sh; m -j${nprocs} prereqs dist; exit \$?'"
}
stage('Deploy') {
def imagePath = "/var/lib/aptly/images/${boardName}/${releaseName}"
def files = findFiles(glob: "out/**/dist/*")
if (files.size() == 0) {
error 'No dist files generated. Assuming failed build.'
}
sh "mkdir -p ${imagePath}"
for (file in files) {
sh "cp ${file} ${imagePath}"
}
}
}
}
}
}
}