blob: bb8e77100e7d6841a3f82114d91038eaf0fb2dbf [file] [log] [blame]
#!/usr/bin/env groovy
enum Repository {
CORE, BSP
String toOutDirName() {
return this.name().toLowerCase()
}
String toRepoDirName(String boardName) {
if (this == Repository.CORE) {
return this.name().toLowerCase()
} else {
return "${this.name().toLowerCase()}-${boardName}"
}
}
};
def initSourceTree(boardName, needsNative = false) {
sh """
apt-get update
apt-get -y install make python curl git qemu-user-static sudo
curl https://storage.googleapis.com/git-repo-downloads/repo > /usr/local/bin/repo
chmod a+x /usr/local/bin/repo
mkdir -p .repo/local_manifests
mkdir -p cache
chmod 777 cache
"""
timeout(time: 3, unit: 'MINUTES') {
checkout([$class: 'RepoScm',
currentBranch: true,
jobs: 24,
manifestRepositoryUrl: 'http://coral.googlesource.com/manifest',
manifestBranch: 'master',
manifestFile: "${boardName}.xml",
depth: 1,
quiet: true])
}
// Bring in the pbuilder tarballs.
//
// archiveArtifacts includes the relative path to the
// files we archive, so we don't have to specify cache/
// here in the target.
if (needsNative) {
copyArtifacts(projectName: 'global.pbuilder.native', filter: '**/*.tgz')
} else {
copyArtifacts(projectName: 'global.pbuilder.cross', filter: '**/*.tgz')
}
}
def buildTarget(targetName) {
sh "bash -c 'source build/setup.sh; m prereqs ${targetName}; exit \$?'"
}
def archivePackage(boardName, packageName, repo = Repository.CORE) {
def archivePath = "pool/${repo.toRepoDirName(boardName)}"
sh """
mkdir -p ${archivePath}
cp src/out/target/product/*/packages/${repo.toOutDirName()}/${packageName}_* ${archivePath}
"""
archiveArtifacts(
artifacts: "${archivePath}/*",
fingerprint: true)
}
def buildPackagePipeline(boardName, packageName, repo = Repository.CORE, needsNative = false) {
def workspacePath = "/home/jenkins/workspace"
def buildLabel = "build-${packageName}-${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: 'debian:buster-slim',
command: 'cat',
ttyEnabled: true,
privileged: true)
podTemplate(label: buildLabel, containers: [jnlpContainer, debianContainer], envVars: []) {
node(buildLabel) {
dir(sourcePath) {
stage('Init') {
container('debian') {
sh 'echo ==================== directory contents; ls'
deleteDir()
initSourceTree(boardName, needsNative)
}
}
stage('Build') {
container('debian') {
buildTarget(packageName)
}
}
}
dir(workspacePath) {
stage('Deploy') {
archivePackage(boardName, packageName, repo)
}
}
}
}
}