| #!/usr/bin/env groovy |
| |
| def initSourceTree(boardName, needsNative = false) { |
| sh """ |
| apt-get update |
| apt-get -y install make python curl git qemu-user-static sudo python3 python3-pip |
| curl https://storage.googleapis.com/git-repo-downloads/repo > /usr/local/bin/repo |
| chmod a+x /usr/local/bin/repo |
| |
| pip3 install aptly-ctl==0.9 |
| |
| git clone https://gerrit.googlesource.com/gcompute-tools /tmp/gcompute-tools |
| /tmp/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) { |
| def outPath = repoType |
| def repoName = nameFromRepoType(repoType, boardName) |
| def packageFilenames = findFiles(glob: '**/*.deb') |
| |
| for file in packageFilenames { |
| sh """ |
| echo Uploading ${file.path} |
| /usr/local/bin/aptly-ctl -C url=http://aptly-api/api \ |
| -C signing.gpgkey=none \ |
| -C signing.passphrase=none \ |
| put unstable-${repoName} ${file.path}; |
| """ |
| } |
| } |
| |
| def buildPackagePipeline(boardName, repoType, packageName, needsNative = false) { |
| def workspacePath = "/home/jenkins/workspace" |
| def buildLabel = "${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', |
| args: '', |
| ttyEnabled: true, |
| privileged: true) |
| |
| podTemplate(label: buildLabel, containers: [jnlpContainer, debianContainer], envVars: []) { |
| node(buildLabel) { |
| dir(sourcePath) { |
| container('debian') { |
| stage('Init') { |
| initSourceTree(boardName, needsNative) |
| } |
| |
| stage('Build') { |
| buildTarget(packageName) |
| } |
| |
| stage('Deploy') { |
| uploadAllGeneratedPackages(repoType, boardName) |
| } |
| } |
| } |
| } |
| } |
| } |