]> git.ozlabs.org Git - petitboot/commitdiff
jenkins: Add build jobs
authorGeoff Levand <geoff@infradead.org>
Thu, 24 May 2018 00:25:57 +0000 (17:25 -0700)
committerSamuel Mendoza-Jonas <sam@mendozajonas.com>
Thu, 26 Jul 2018 00:10:30 +0000 (10:10 +1000)
Adds two Jenkins pipeline jobs pb-upstream-trigger and pb-build-matrix.
pb-upstream-trigger checks for upstream updates and runs
pb-build-matrix.  pb-build-matrix builds a pb-builder image and runs the
build-pb script.

Signed-off-by: Geoff Levand <geoff@infradead.org>
Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
jenkins/pb-build-matrix.groovy [new file with mode: 0644]
jenkins/pb-upstream-trigger.groovy [new file with mode: 0644]

diff --git a/jenkins/pb-build-matrix.groovy b/jenkins/pb-build-matrix.groovy
new file mode 100644 (file)
index 0000000..7547612
--- /dev/null
@@ -0,0 +1,81 @@
+#!groovy
+// Builds pb-builder image and runs build-pb script.
+//
+// The `jenkins` user must be in the `docker` user group.
+// Requires nodes with labels: `amd64`, `arm64`, `docker`.
+// Required plugins: build-timeout, copyartifact, git, pipeline, ssh-agent,
+// workflow-aggregator.
+
+properties([
+    buildDiscarder(logRotator(daysToKeepStr: '30', numToKeepStr: '5')),
+    parameters([
+    string(name: 'BUILD_ARCH_LIST',
+        defaultValue: 'amd64 arm64',
+        description: 'List of Jenkins node architectures to build on.'),
+    booleanParam(name: 'DOCKER_PURGE',
+        defaultValue: false,
+        description: 'Remove existing pb-builder docker image and rebuild.'),
+    booleanParam(name: 'DRY_RUN',
+        defaultValue: false,
+        description: 'Dry run, do not build.'),
+    string(name: 'GIT_URL',
+        defaultValue: 'git://ozlabs.org/petitboot',
+        description: 'URL of petitboot git repository.'),
+    ])
+])
+
+def build_pb = { String _build_arch, Boolean _dry_run, String _git_url,
+    Boolean _purge
+    ->
+    String build_arch = _build_arch
+    Boolean dry_run = _dry_run
+    String git_url = _git_url
+    Boolean purge = _purge
+    String builder_args = ""
+    String pb_args = ""
+
+    if (dry_run) {
+        builder_args += " --dry-run"
+        pb_args += " --dry-run"
+    }
+    if (purge) {
+        builder_args += " --purge"
+    }
+
+    // timeout if no build_arch node is available.
+    timeout(time: 15, unit: 'MINUTES') {
+        node("${build_arch} && docker") {
+            git(poll: false, changelog: false, url: git_url)
+
+            stage("[${build_arch}--build-builder]") {
+                sh("""./docker/build-builder --verbose ${builder_args}""")
+            }
+            stage("[${build_arch}--build-pb]") {
+                sh("""./docker/build-pb --verbose --check ${pb_args}""")
+            }
+            stage('Post-build') {
+                String result_file = "${BUILD_TAG}-${build_arch}-test-results.tar.xz"
+                String test_info = """build_arch=${build_arch}
+    BUILD_URL=${BUILD_URL}
+    BUILD_TAG=${BUILD_TAG}
+    GIT_URL=${GIT_URL}
+    """
+
+                writeFile(file: 'test-info.txt', text: test_info)
+                sh("tar -cJf ${result_file} test-info.txt test-suite.log \
+                    \$(find test -name '*.log')")
+                archiveArtifacts  "${result_file}"
+            }
+        }
+    }
+}
+
+def build_map = [:]
+build_map.failFast = false
+
+for (build_arch in params.BUILD_ARCH_LIST.split()) {
+    build_map[build_arch] = build_pb.curry(build_arch, params.DRY_RUN,
+        params.GIT_URL, params.DOCKER_PURGE)
+}
+
+parallel build_map
diff --git a/jenkins/pb-upstream-trigger.groovy b/jenkins/pb-upstream-trigger.groovy
new file mode 100644 (file)
index 0000000..ab67e74
--- /dev/null
@@ -0,0 +1,24 @@
+#!groovy
+// Check for upstream updates and run builds.
+
+properties([
+    buildDiscarder(logRotator(daysToKeepStr: '30', numToKeepStr: '5')),
+    pipelineTriggers([pollSCM('H/30 * * * *')]),
+    parameters([
+    string(name: 'GIT_URL',
+        defaultValue: 'git://ozlabs.org/petitboot',
+        description: 'URL of petitboot git repository.'),
+    ])
+])
+
+stage('Build') {
+    node {
+        git(poll: true, changelog: false, url: params.GIT_URL)
+        build(
+            job: 'pb-build-matrix',
+            parameters: [
+                string(name: 'GIT_URL', value: params.GIT_URL),
+            ],
+        )
+    }
+}