Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: issue with jenkinsfile not aborting if gha is aborted #18541

Merged
merged 3 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .github/workflows/precommit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,17 @@ jobs:
with:
name: 'build-artifact'

- 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

- name: Deploy to precommit environment
id: deploy
if: ${{ needs.build.outputs.total_additions > 100 && github.actor != 'dependabot[bot]' }}
uses: einaregilsson/beanstalk-deploy@v22
with:
application_name: Webapp
Expand Down
39 changes: 23 additions & 16 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -85,27 +85,34 @@ 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') {
echo("GitHub Action was cancelled. Ending Jenkins pipeline.")
return true
}

return result
}
}
}
}
}
}
}
}

stage('Check deployment') {
steps {
Expand Down
Loading