Home > Software engineering >  Error while Running the SonarQube Quality Gate via GitHub Actions
Error while Running the SonarQube Quality Gate via GitHub Actions

Time:01-05

I just integrated the Sonarqube with Github .. Used Github actions for integration with the sonarqube in which sonarqube quality gate template is used as the pipeline script and the over each pull request the sonarqube will check the code and will give the status.. Error is coming if I run this pipeline in github actions

This is the workflow file and the error is given below

name: SonarQube Qualitygate check
on:
  # Trigger analysis when pushing in master or pull requests, and when creating
  # a pull request. 
  push:
    branches:
      - development
  pull_request:
      types: [opened, synchronize, reopened]
jobs:
  sonarqube:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
      with:
        # Disabling shallow clone is recommended for improving relevancy of reporting.
        fetch-depth: 0

    - name: SonarQube Quality Gate check
      uses: sonarsource/sonarqube-quality-gate-action@master
      with:
        scanMetadataReportFile: target/sonar/report-task.txt

    # Triggering SonarQube analysis as results of it are required by Quality Gate check.
    - name: SonarQube Scan
      uses: SonarSource/sonarqube-scan-action@master
      with:
        projectBaseDir: .
      env:
        SONAR_TOKEN: ${{ secrets.TM_SONAR_TOKEN }}
        SONAR_HOST_URL: ${{ secrets.TM_SONAR_HOST_URL }}

    # Check the Quality Gate status.
    - name: SonarQube Quality Gate check
      id: 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.TM_SONAR_TOKEN }}
       SONAR_HOST_URL: ${{ secrets.TM_SONAR_HOST_URL }}

This is the error which i get while executing the pipeline

enter image description here

CodePudding user response:

From the docs on the action: https://github.com/sonarsource/sonarqube-quality-gate-action, it seems like you need to first run the sonarqube-scan-action and then run the sonarqube-quality-gate-action. You have that order the other way around.

CodePudding user response:

updated one

name: SonarQube Qualitygate check
on:
  # Trigger analysis when pushing in master or pull requests, and when creating
  # a pull request. 
  push:
    branches:
      - development
  pull_request:
      types: [opened, synchronize, reopened]
jobs:
  sonarqube:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
      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
      with:
        projectBaseDir: .
      env:
        SONAR_TOKEN: ${{ secrets.TM_SONAR_TOKEN }}
        SONAR_HOST_URL: ${{ secrets.TM_SONAR_HOST_URL }}

    # Check the Quality Gate status.
    - name: SonarQube Quality Gate check
      id: sonarqube-quality-gate-check
      uses: SonarSource/sonarqube-quality-gate-action@master 
      # Force to fail step after specific time.
      timeout-minutes: 5
      env:
        SONAR_LOGIN: ${{ secrets.TM_SONAR_TOKEN }}
        SONAR_HOST_URL: ${{ secrets.TM_SONAR_HOST_URL }}
  • Related