From e23e43014f41e1a6b99198bc6e3b81f895ab0f3d Mon Sep 17 00:00:00 2001 From: mahmutovicr Date: Fri, 15 May 2026 00:56:58 +0200 Subject: [PATCH] jenkins: add event-relay pipeline to GitHub API directly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replaces the HTTP POST to the GitHub bot event-relay endpoint with direct GitHub API calls, as part of removing the bot infrastructure. Refs: https://github.com/nodejs/node/issues/51236 Signed-off-by: Rahman Mahmutović --- .../pipelines/jenkins-event-relay.jenkinsfile | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 jenkins/pipelines/jenkins-event-relay.jenkinsfile diff --git a/jenkins/pipelines/jenkins-event-relay.jenkinsfile b/jenkins/pipelines/jenkins-event-relay.jenkinsfile new file mode 100644 index 000000000..aee3e0a54 --- /dev/null +++ b/jenkins/pipelines/jenkins-event-relay.jenkinsfile @@ -0,0 +1,83 @@ +#!/usr/bin/env groovy + +// DESCRIPTION: +// Relays Jenkins events directly to GitHub as repository_dispatch events. +// Replaces the HTTP POST to the GitHub bot with a direct GitHub API call. +// Primarily used to trigger GitHub Actions workflows based on Jenkins events. + +import groovy.json.JsonOutput + +pipeline { + agent { label 'jenkins-workspace' } + + parameters { + string(defaultValue: 'nodejs', description: 'GitHub organization', name: 'OWNER') + string(defaultValue: 'node', description: 'GitHub repository', name: 'REPO') + string(defaultValue: '', description: 'Jenkins job identifier', name: 'IDENTIFIER') + string(defaultValue: '', description: 'Jenkins event type (e.g. start, end)', name: 'EVENT') + } + + stages { + stage('Relay event') { + steps { + validateParams(params) + timeout(activity: true, time: 30, unit: 'SECONDS') { + relayEvent(params.OWNER, params.REPO, params.IDENTIFIER, params.EVENT) + } + } + } + } +} + +def relayEvent(owner, repo, identifier, event) { + def eventType = "jenkins.${identifier}.${event}" + + def payload = JsonOutput.toJson([ + 'event_type': eventType, + 'client_payload': [ + 'owner': owner, + 'repo': repo, + 'identifier': identifier, + 'event': event, + ], + ]) + + println(payload) + + def response + try { + withCredentials([string(credentialsId: 'GITHUB_TOKEN', variable: 'GITHUB_TOKEN')]) { + response = httpRequest( + url: "https://api.github.com/repos/${owner}/${repo}/dispatches", + httpMode: 'POST', + timeout: 30, + contentType: 'APPLICATION_JSON_UTF8', + customHeaders: [ + [ + name: 'Authorization', + value: "Bearer ${GITHUB_TOKEN}", + maskValue: true, + ], + [ + name: 'Accept', + value: 'application/vnd.github+json', + maskValue: false, + ], + ], + requestBody: payload + ) + } + } catch (Exception e) { + println(e.toString()) + if (response) { + println('Status: ' + response.status) + println('Content: ' + response.content) + } + } +} + +def validateParams(params) { + if (params.IDENTIFIER == '' || params.EVENT == '') { + error('IDENTIFIER and EVENT parameters are required.') + } +}