From 1ff7b427f76cc1a8910f0f39808a448b2d4c0ad7 Mon Sep 17 00:00:00 2001 From: Timothy Le Bon Date: Thu, 19 Dec 2024 15:41:45 +0100 Subject: [PATCH 1/3] 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 { From dc42b9e72e183177b7a2395a1ea1e58aad90a87d Mon Sep 17 00:00:00 2001 From: Timothy Le Bon Date: Thu, 19 Dec 2024 16:44:46 +0100 Subject: [PATCH 2/3] chore: make GHA cancel not throw an error for the pipeline --- .github/workflows/precommit.yml | 7 ++++++- Jenkinsfile | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/precommit.yml b/.github/workflows/precommit.yml index 115ed732d90..50ecf84812f 100644 --- a/.github/workflows/precommit.yml +++ b/.github/workflows/precommit.yml @@ -84,7 +84,12 @@ jobs: - name: Deploy to precommit environment id: deploy - if: ${{ needs.build.outputs.total_additions > 100 && github.actor != 'dependabot[bot]' }} + if: ${{ always() }} + run: | + if [[ ${{ needs.build.outputs.total_additions }} -le 100 || "${{ github.actor }}" == "dependabot[bot]" ]]; then + echo "Skipping deployment" + exit 0 + fi uses: einaregilsson/beanstalk-deploy@v22 with: application_name: Webapp diff --git a/Jenkinsfile b/Jenkinsfile index 62abf64bf26..c17ab7f5b22 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -102,8 +102,10 @@ pipeline { return workflowRuns.any { run -> def result = checkWorkflowRun(run, commit_hash) if (run['conclusion'] == 'cancelled') { - error("GitHub Action was cancelled. Aborting Jenkins pipeline.") + echo("GitHub Action was cancelled. Ending Jenkins pipeline.") + return true } + return result } } From 5edbdf9f60284c1ae0402044b36c5cb98e63d7c7 Mon Sep 17 00:00:00 2001 From: Timothy Le Bon Date: Thu, 19 Dec 2024 17:06:59 +0100 Subject: [PATCH 3/3] fix: issue with run and uses keywords --- .github/workflows/precommit.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/precommit.yml b/.github/workflows/precommit.yml index 50ecf84812f..94fd118d4f5 100644 --- a/.github/workflows/precommit.yml +++ b/.github/workflows/precommit.yml @@ -82,14 +82,17 @@ jobs: with: name: 'build-artifact' - - name: Deploy to precommit environment - id: deploy + - name: Check if deploy is necessary + id: check_deploy if: ${{ always() }} run: | if [[ ${{ needs.build.outputs.total_additions }} -le 100 || "${{ github.actor }}" == "dependabot[bot]" ]]; then echo "Skipping deployment" exit 0 - fi + fi + + - name: Deploy to precommit environment + id: deploy uses: einaregilsson/beanstalk-deploy@v22 with: application_name: Webapp