Bitbucket sonar pipe fails with error "SonarCloud Analysis Failed" despite successful execution of sonar run

Platform Notice: Cloud Only - This article only applies to Atlassian products on the cloud platform.

Summary

When using the Sonar pipe in Bitbucket, one may encounter an issue where the build process fails with the error message "SonarCloud analysis failed," even though the execution of the pipeline appears to be successful. This error can be frustrating, but there is a solution.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 02:59:09.058 INFO: ANALYSIS SUCCESSFUL, you can find the results at: https://sonarcloud.io/dashboard?id=ehgprojecthorizon_fp-payment-schedule-batch-processor-lambda&branch=development 02:59:09.058 INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report 02:59:09.058 INFO: More about the report processing at https://sonarcloud.io/api/ce/task?id=AYPzVI-n3yNJmTqUnuXp 02:59:09.063 DEBUG: Post-jobs : 02:59:09.068 DEBUG: eslint-bridge server will shutdown 02:59:14.071 DEBUG: eslint-bridge server closed 02:59:14.634 INFO: Analysis total time: 30.106 s 02:59:14.636 INFO: ------------------------------------------------------------------------ 02:59:14.636 INFO: EXECUTION SUCCESS 02:59:14.636 INFO: ------------------------------------------------------------------------ 02:59:14.637 INFO: Total time: 42.489s 02:59:14.722 INFO: Final Memory: 47M/180M 02:59:14.722 INFO: ------------------------------------------------------------------------ e[31m✖ SonarCloud analysis failed. (exit code = 1)e[0m Searching for files matching artifact pattern .bitbucket/pipelines/generated/pipeline/pipes/** Artifact pattern .bitbucket/pipelines/generated/pipeline/pipes/** matched 1 files with a total size of 189.1 KiB Compressed files matching artifact pattern .bitbucket/pipelines/generated/pipeline/pipes/** to 22 KiB in 0 seconds Uploading artifact of 22 KiB Successfully uploaded artifact in 0 seconds

Cause

This error typically occurs when subsequent pipeline steps, such as the one mentioned in the example below, attempt to access the same directories, leading to permission issues that ultimately result in the analysis failure.

Example Pipeline Configuration:

1 2 3 4 5 6 7 8 9 10 pipelines: default: - step: name: Step 1 script: - pipe: sonarsource/sonarcloud-scan:2.0.0 - step: name: Step 2 script: - pipe: sonarsource/sonarcloud-scan:2.0.0

In the provided example, "Step 2" may fail due to permission issues. To troubleshoot and resolve this problem, consider adding debug information to your pipeline and check if any messages similar to the one below are printed:

1 /opt/atlassian/pipelines/agent/build/.bitbucket/pipelines/generated/pipeline/pipes/sonarsource/sonarcloud-scan/sonarcloud-scan.log: Permission denied

To enable debug mode for the SonarCloud scan, you can add the following configuration to your pipeline YAML:

1 - pipe: sonarsource/sonarcloud-scan:2.0.0 variables: DEBUG: "true"

Solution

The proposed solution involves removing the directory that the Sonar pipe is attempting to write to before the "Step 2" pipe runs, especially if the problem is confirmed to be related to permissions issues based on the logs.

Here's an example of how to remove the directory before running the SonarCloud scan:

1 script: - rm -rf /opt/atlassian/pipelines/agent/build/.bitbucket/pipelines/generated/pipeline/pipes - pipe: sonarsource/sonarcloud-scan:2.0.0

By implementing this solution, you can resolve the "SonarCloud analysis failed" error and ensure the successful execution of your Bitbucket Sonar pipe.

If you are encountering issues following this documentation - please raise a support ticket or a community support ticket for further assistance.

Updated on April 11, 2025

Still need help?

The Atlassian Community is here for you.