From 1ff7b427f76cc1a8910f0f39808a448b2d4c0ad7 Mon Sep 17 00:00:00 2001 From: Timothy Le Bon Date: Thu, 19 Dec 2024 15:41:45 +0100 Subject: [PATCH] fix: issue with jenkinsfile not aborting if gha is aborted --- Jenkinsfile | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 4746d4d307d..62abf64bf26 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -85,27 +85,32 @@ pipeline { } } } - - stage('Check GitHub Action Status') { - when { expression { BRANCH_NAME ==~ /PR-[0-9]+/ } } - steps { + stage('Check GitHub Action Status') { + when { expression { BRANCH_NAME ==~ /PR-[0-9]+/ } } + steps { timeout(time: 15, unit: 'MINUTES') { - script { - def commit_hash = sh(script: 'git rev-parse HEAD', returnStdout: true).trim() - final String apiUrl = 'https://api.github.com/repos/wireapp/wire-webapp/actions/workflows/128602012/runs' - final String curlCmd = "curl -u \${CREDENTIALS} ${apiUrl}" - waitUntil { - final String output = sh(label: 'Check workflow', returnStdout: true, script: curlCmd) - final Object jsonData = readJSON(text: output) - final List workflowRuns = jsonData['workflow_runs'] - echo("Looking for hash ${commit_hash}") + script { + def commit_hash = sh(script: 'git rev-parse HEAD', returnStdout: true).trim() + final String apiUrl = 'https://api.github.com/repos/wireapp/wire-webapp/actions/workflows/128602012/runs' + final String curlCmd = "curl -u \${CREDENTIALS} ${apiUrl}" + waitUntil { + final String output = sh(label: 'Check workflow', returnStdout: true, script: curlCmd) + final Object jsonData = readJSON(text: output) + final List workflowRuns = jsonData['workflow_runs'] + echo("Looking for hash ${commit_hash}") - return workflowRuns.any { run -> checkWorkflowRun(run, commit_hash) } + return workflowRuns.any { run -> + def result = checkWorkflowRun(run, commit_hash) + if (run['conclusion'] == 'cancelled') { + error("GitHub Action was cancelled. Aborting Jenkins pipeline.") + } + return result + } + } + } } } - } } - } stage('Check deployment') { steps {