]> git.apps.os.sepia.ceph.com Git - ceph-build.git/commitdiff
Add ceph-dev-pipeline-trigger
authorZack Cerza <zack@redhat.com>
Thu, 23 Jan 2025 21:21:43 +0000 (14:21 -0700)
committerZack Cerza <zack@cerza.org>
Wed, 5 Feb 2025 19:53:39 +0000 (12:53 -0700)
This job serves to trigger ceph-dev-pipeline via webhook payloads, but is
opt-in. This implementation initially targets only GitHub push event payloads.
On each push, it will inspect the head commit for [git trailers][0]. The trailer
required to opt in is "CI-PIPELINE: true". If that trailer is found, the job
looks for these others:

ARCHS, CI_COMPILE, CI_CONTAINER, CI_PIPELINE, DISTROS, DWZ, FLAVOR, SCCACHE

Any that are found are passed as parameters.

[0] https://git-scm.com/docs/git-interpret-trailers

Signed-off-by: Zack Cerza <zack@cerza.org>
ceph-dev-pipeline-trigger/build/Jenkinsfile [new file with mode: 0644]
ceph-dev-pipeline-trigger/config/definitions/ceph-dev-pipeline-trigger.yml [new file with mode: 0644]

diff --git a/ceph-dev-pipeline-trigger/build/Jenkinsfile b/ceph-dev-pipeline-trigger/build/Jenkinsfile
new file mode 100644 (file)
index 0000000..e53b8fb
--- /dev/null
@@ -0,0 +1,58 @@
+JOB = "ceph-dev-pipeline"
+VALID_PARAMETERS = [
+  "ARCHS",
+  "CI_COMPILE",
+  "CI_CONTAINER",
+  "CI_PIPELINE",
+  "DISTROS",
+  "DWZ",
+  "FLAVOR",
+  "SCCACHE",
+]
+def params = []
+
+pipeline {
+  agent any
+  stages {
+    stage("Prepare parameters") {
+      steps {
+        script {
+          def trailer = sh(
+            script: "echo \"$head_commit\" | git interpret-trailers --parse",
+            returnStdout: true,
+          )
+          println("trailer: ${trailer}")
+          def paramsMap = [:]
+          for (item in trailer.split("\n")) {
+            def matcher = item =~ /(.+): (.+)/
+            if (matcher.matches()) {
+              key = matcher[0][1].replace("-", "_").toUpperCase()
+              value = matcher[0][2]
+              paramsMap[key] = value
+            }
+          }
+          def branch = env.ref.replace("refs/heads/", "")
+          params.push(string(name: "BRANCH", value: branch))
+          println("Looking for parameters: ${VALID_PARAMETERS}")
+          for (key in VALID_PARAMETERS) {
+            value = paramsMap[key]
+            if ( value ) {
+              params.push(string(name: key, value: value))
+              println("${key}=${value}")
+            }
+          }
+        }
+      }
+    }
+    stage("Trigger job") {
+      steps {
+        script {
+          build(
+            job: JOB,
+            parameters: params
+          )
+        }
+      }
+    }
+  }
+}
diff --git a/ceph-dev-pipeline-trigger/config/definitions/ceph-dev-pipeline-trigger.yml b/ceph-dev-pipeline-trigger/config/definitions/ceph-dev-pipeline-trigger.yml
new file mode 100644 (file)
index 0000000..39fab9c
--- /dev/null
@@ -0,0 +1,40 @@
+- job:
+    name: ceph-dev-pipeline-trigger
+    project-type: pipeline
+    quiet-period: 1
+    concurrent: true
+    pipeline-scm:
+      scm:
+        - git:
+            url: https://github.com/ceph/ceph-build
+            branches:
+              - jenkinsfile
+            shallow-clone: true
+            submodule:
+              disable: true
+            wipe-workspace: true
+      script-path: ceph-dev-pipeline-trigger/build/Jenkinsfile
+      lightweight-checkout: true
+      do-not-fetch-tags: true
+
+    triggers:
+      - generic-webhook-trigger:
+          token: ceph-dev-pipeline-trigger
+          token-credential-id: pipeline-trigger-token
+          print-contrib-var: true
+          header-params:
+            - key: X_GitHub_Event
+              value: ""
+          post-content-params:
+            - type: JSONPath
+              key: head_commit
+              value: $.head_commit.message
+            - type: JSONPath
+              key: ref
+              value: $.ref
+            - type: JSONPath
+              key: pusher
+              value: $.pusher.name
+          regex-filter-text: $head_commit
+          regex-filter-expression: "(?i)CI-PIPELINE: true"
+          cause: "Push to $ref by $pusher"