diff --git a/Jenkinsfile.trigger b/Jenkinsfile.trigger index 30a71d1..92a9c2b 100644 --- a/Jenkinsfile.trigger +++ b/Jenkinsfile.trigger @@ -57,6 +57,7 @@ node { queueJson = sh(returnStdout: true, script: ''' jq -L.scripts ' include "meta"; + include "jenkins"; (env.pastFailedJobsJson | fromjson) as $pastFailedJobs | [ .[] @@ -70,6 +71,7 @@ node { | index($arch) ) ) + | .payload = (gha_payload | @json) ] # this Jenkins job exports a JSON file that includes the number of attempts so far per failing buildId so that this can sort by attempts which means failing builds always live at the bottom of the queue (sorted by the number of times they have failed, so the most failing is always last) | sort_by($pastFailedJobs[.buildId].count // 0) @@ -85,52 +87,6 @@ node { breakEarly = true return } - - // for GHA builds, we still need a node (to curl GHA API), so we'll handle those here - if (env.BASHBREW_ARCH == 'gha') { - withCredentials([ - string( - variable: 'GH_TOKEN', - credentialsId: 'github-access-token-docker-library-bot-meta', - ), - ]) { - for (buildObj in queue) { - def identifier = buildObj.source.arches[buildObj.build.arch].tags[0] + ' (' + buildObj.build.arch + ')' - def json = writeJSON(json: buildObj, returnText: true) - withEnv([ - 'json=' + json, - ]) { - stage(identifier) { - echo(json) // for debugging/data purposes - - sh '''#!/usr/bin/env bash - set -Eeuo pipefail -x - - # https://docs.github.com/en/free-pro-team@latest/rest/actions/workflows?apiVersion=2022-11-28#create-a-workflow-dispatch-event - payload="$( - jq <<<"$json" -L.scripts ' - include "jenkins"; - gha_payload - ' - )" - - set +x - curl -fL \ - -X POST \ - -H 'Accept: application/vnd.github+json' \ - -H "Authorization: Bearer $GH_TOKEN" \ - -H 'X-GitHub-Api-Version: 2022-11-28' \ - https://api.github.com/repos/docker-library/meta/actions/workflows/build.yml/dispatches \ - -d "$payload" - ''' - } - } - } - } - // we're done triggering GHA, so we're completely done with this job - breakEarly = true - return - } } } @@ -142,13 +98,40 @@ def newFailedJobs = [:] for (buildObj in queue) { def identifier = buildObj.source.arches[buildObj.build.arch].tags[0] - def json = writeJSON(json: buildObj, returnText: true) - withEnv([ - 'json=' + json, - ]) { - stage(identifier) { - echo(json) // for debugging/data purposes + if (env.BASHBREW_ARCH == 'gha') { + identifier += ' (' + buildObj.build.arch + ')' + } + stage(identifier) { + def json = writeJSON(json: buildObj, returnText: true) + echo(json) // for debugging/data purposes + if (env.BASHBREW_ARCH == 'gha') { + node { + withEnv([ + 'payload=' + buildObj.payload + ]) { + withCredentials([ + string( + variable: 'GH_TOKEN', + credentialsId: 'github-access-token-docker-library-bot-meta', + ), + ]) { + sh ''' + set -Eeuo pipefail + + # https://docs.github.com/en/free-pro-team@latest/rest/actions/workflows?apiVersion=2022-11-28#create-a-workflow-dispatch-event + curl -fL \ + -X POST \ + -H 'Accept: application/vnd.github+json' \ + -H "Authorization: Bearer $GH_TOKEN" \ + -H 'X-GitHub-Api-Version: 2022-11-28' \ + https://api.github.com/repos/docker-library/meta/actions/workflows/build.yml/dispatches \ + -d "$payload" + ''' + } + } + } + } else { def res = build( job: 'build-' + env.BASHBREW_ARCH, parameters: [ @@ -172,11 +155,11 @@ for (buildObj in queue) { url: res.absoluteUrl, endTime: (res.startTimeInMillis + res.duration) / 1000.0, // convert to seconds ] - - // "catchError" is the only way to set "stageResult" :( - catchError(message: 'Build of "' + identifier + '" failed', buildResult: 'UNSTABLE', stageResult: 'FAILURE') { error() } } } + + // "catchError" is the only way to set "stageResult" :( + catchError(message: 'Build of "' + identifier + '" failed', buildResult: 'UNSTABLE', stageResult: 'FAILURE') { error() } } }