Bitbucket Pipelines

Hi, I am trying to get the result of the analysis performed by sonar, to validate if there are critical errors and report them as failure.
So far the analysis is correct, but if sonar identifies that there are critical errors in the code I can’t fail the pipeline, and I need it to fail.

This mi pipeline
image: maven:3.3.9

definitions:
  steps:
    - step: &build-step
        name: SonarQube analysis
        script:
          - pipe: sonarsource/sonarqube-scan:2.0.1
            variables:
              SONAR_HOST_URL: ${SONAR_HOST_URL}
              SONAR_TOKEN: ${SONAR_TOKEN}
  caches:
    sonar: ~/.sonar

clone:
  depth: full

pipelines:
  branches:
    '{master}':
      - step: *build-step
      - step:
          name: Check SonarQube Analysis
          script:
            - if [ -f report-task.txt ]; then
                ERROR_COUNT=$(grep -c 'CRITICAL\|ERROR' report-task.txt);
                if [ $ERROR_COUNT -gt 0 ]; then
                  echo "Failing the pipeline due to critical errors in SonarQube analysis.";
                  exit 1;
                fi
              else
                echo "report-task.txt file not found. Failing the pipeline.";
                exit 1;
              fi

resultado:

  • SonarQube analysis (OK).
  • Check SonarQube Analysis (fail).
`if [ -f report-task.txt ]; then ERROR_COUNT=$(grep -c 'CRITICAL\|ERROR' report-task.txt); 
if [ $ERROR_COUNT -gt 0 ]; then 
echo "Failing the pipeline due to critical errors in SonarQube analysis."; exit 1; 
fi else echo "report-task.txt file not found. Failing the pipeline."; exit 1; fi`
`report-task.txt file not found. Failing the pipeline.`

I have checked everywhere in the sonar interface to see where I have to configure it, I understand that not all sonarqube versions generate it automatically.

I did this search “find / -name report-task.txt 2>/dev/null” on the server and it doesn’t find it, so I don’t know what is missing or where is the failure.

I need some guidance
Thanks

Hi,

Rather than doing a count of issues and logic on that, what you want to do is set up your Quality Gate to fail when there are Critical issues. Then fail your pipeline based on the Quatliy Gate status. The details of that will vary depending on your CI.

 
HTH,
Ann

Hi Ann.
Thank.
Exactly, what I need is to know the status of the sonar analysis, if it is failure or success, since we will review the details in sonar.
How should I configure my pipeline to do this validation.
thank you for your time.

Hi,

Sorry, I overlooked that your title said ‘Bitbucket’ :flushed:

Here you go.

 
HTH,
Ann