blob: 7fc3d6d4a33c4965acf29fb111ddd6137848377a [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 date = new Date()
String stamp = date.format("yyyyMMdd-HHmmss")
def packages = findFiles(glob: "out/**/${packageName}*.deb")
def sources = findFiles(glob: "out/**/${packageName}*.dsc")
def filenames = (packages + sources).each{entry -> entry.path}
if (filenames.size() == 0) {
error 'No packages were generated! Assuming failed build.'
}
sh """
aptly task run repo add -force-replace unstable-${repoName} ${filenames.join(' ')}, \
snapshot create unstable-${repoName}-${stamp} from repo unstable-${repoName}
"""
}
}
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)
}
}
}
}
}
}