Skip to content

Commit

Permalink
fix: pipeline ending when status is correct
Browse files Browse the repository at this point in the history
  • Loading branch information
tlebon committed Dec 10, 2024
1 parent 931213a commit d29d260
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ pipeline {
}

echo("Wait for github actions to start for ${BRANCH_NAME} against ${changeTargetBranch}")
final def VALID_STATUSES = ['queued', 'in_progress', 'completed']
timeout(time: 45, unit: 'MINUTES') {
waitUntil {
def output = sh label: 'Get runs', returnStdout: true, script: "curl -s -L -H 'Accept: application/vnd.github+json' -H 'Authorization: Bearer ${CREDENTIALS}' -H 'X-GitHub-Api-Version: 2022-11-28' ${targetWorkflowUrl}"
Expand All @@ -69,20 +70,17 @@ pipeline {
}
def runs = json['workflow_runs']
echo('Looking for PR-' + pr_number + ' with hash' + commit_hash)
for (run in runs) {
if (run['head_sha'] == commit_hash) {
echo('Found ' + commit_hash)
echo('status: ' + run['status'])
env.GITHUB_ACTION_URL = run['url'].replace('api.github.com/repos', 'github.com/')
// status can be queued, in_progress, or completed
if (run['status'] == 'queued' || run['status'] == 'in_progress' || run['status'] == 'completed') {
return true
}
}
def matchingRun = runs.find { it['head_sha'] == commit_hash }
if (matchingRun) {
echo('Found ' + commit_hash)
def status = matchingRun['status']
echo('status: ' + status)
env.GITHUB_ACTION_URL = matchingRun['url'].replace('api.github.com/repos', 'github.com/')
return VALID_STATUSES.contains(status)
}
false
}
sleep(20)
return false
sleep(20)
}
}
}
Expand Down

0 comments on commit d29d260

Please sign in to comment.