blob: cd8e07e136fb8c5cb741dd97efd26810ab9b4a24 [file] [log] [blame]
#!/usr/bin/env groovy
def initSourceTree(boardName, needsNative = false) {
sh """
/opt/gcompute-tools/git-cookie-authdaemon
git config --global url.https://aiyprojects.googlesource.com/.insteadOf sso://aiyprojects/
mkdir -p .repo/local_manifests
mkdir -p cache
chmod 777 cache .repo/local_manifests
"""
timeout(time: 20, unit: 'MINUTES') {
checkout([$class: 'RepoScm',
currentBranch: true,
jobs: 24,
manifestRepositoryUrl: 'http://coral.googlesource.com/manifest',
manifestBranch: 'master',
manifestFile: "${boardName}.xml",
manifestGroup: "default,internal",
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.arm64', filter: '**/*.tgz')
copyArtifacts(projectName: 'global.pbuilder.armhf', 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 nameFromRepoType(repoType, boardName) {
if (repoType == "core") {
return "core"
} else if (repoType == "bsp") {
return "bsp-${boardName}"
} else {
error 'Unknown repoType ${repoType}'
}
}
def uploadAllGeneratedPackages(repoType, boardName, packageNames) {
def outPath = repoType
def repoName = nameFromRepoType(repoType, boardName)
for (packageName in packageNames) {
def packages = findFiles(glob: "out/**/${packageName}*.deb")
def sources = findFiles(glob: "out/**/${packageName}*.dsc")
if (packages.size() == 0) {
error 'No packages were generated! Assuming failed build.'
}
for (file in packages) {
sh "aptly repo add -force-replace unstable-${repoName} ${file.path}"
}
for (file in sources) {
sh "aptly repo add -force-replace unstable-${repoName} ${file.path}"
}
}
}
def buildPackagePipeline(boardName, repoType, targetName, packageNames, needsNative = false) {
def workspacePath = "/home/jenkins/workspace"
def buildLabel = "${targetName}-${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') {
stage('Init') {
initSourceTree(boardName, needsNative)
}
stage('Build') {
buildTarget(targetName)
}
stage('Deploy') {
uploadAllGeneratedPackages(repoType, boardName, packageNames)
}
}
}
}
}
}