From a1f88660d55d53c1c6d1d9b866bc5a53996d3569 Mon Sep 17 00:00:00 2001 From: Zack Cerza Date: Thu, 23 Jan 2025 14:21:43 -0700 Subject: [PATCH] Add ceph-dev-pipeline-trigger 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 --- ceph-dev-pipeline-trigger/build/Jenkinsfile | 58 +++++++++++++++++++ .../definitions/ceph-dev-pipeline-trigger.yml | 40 +++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 ceph-dev-pipeline-trigger/build/Jenkinsfile create mode 100644 ceph-dev-pipeline-trigger/config/definitions/ceph-dev-pipeline-trigger.yml diff --git a/ceph-dev-pipeline-trigger/build/Jenkinsfile b/ceph-dev-pipeline-trigger/build/Jenkinsfile new file mode 100644 index 00000000..e53b8fbc --- /dev/null +++ b/ceph-dev-pipeline-trigger/build/Jenkinsfile @@ -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 index 00000000..39fab9cd --- /dev/null +++ b/ceph-dev-pipeline-trigger/config/definitions/ceph-dev-pipeline-trigger.yml @@ -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" -- 2.39.5