如何在SonarQube扫描失败时停止GitHub Action构建



我有一个扫描步骤内置到我的GitHub行动构建,这是工作良好。我联系公司的SonarQub实例,扫描就启动了。我遇到的问题是,如果有失败,试图停止构建。无论如何,我似乎找不到这样做的方法。此外,当我看扫描它似乎好像下一步可能发生在它完成之前(不是积极的,但我认为我会提到它)。有什么想法?

name: Build, test, & deploy
on: [push]
jobs:
sonarqube:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
# Disabling shallow clone is recommended for improving relevancy of reporting
fetch-depth: 0
# Triggering SonarQube analysis as results of it are required by Quality Gate check
- name: SonarQube Scan
uses: sonarsource/sonarqube-scan-action@master
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
- name: SonarQube Quality Gate check
uses: sonarsource/sonarqube-quality-gate-action@master
# Force to fail step after specific time
timeout-minutes: 5
env:
SONAR_TOKEN: ${{ secrets.ADAM_SONAR_TOKEN }}
build:
name:  Project build & package
if: "!contains(github.even.head_commit.message, '[skip-ci]')"
runs-on: ubuntu-latest
env:
#environment var for this job
#### the rest of the build is below this area - I didn't think it was necessary to include

您应该在构建作业中使用需求:

build:
needs: sonarqube
name:  Project build & package

您可以在这里找到信息:https://docs.github.com/en/actions/using-jobs/using-jobs-in-a-workflow

答案是使用"needs": https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idneeds