We are encountering an issue with our Azure DevOps pipeline while publishing SonarCloud analysis results. The error message is as follows (SonarCloudPublish):
##[error][ERROR] SonarQube Cloud: Error while executing task Publish: Task failed with status FAILED, Error message: Invalid branch type ‘SHORT’. Branch ‘develop’ already exists with type ‘LONG’.
##[error]Task failed with status FAILED, Error message: Invalid branch type ‘SHORT’. Branch ‘develop’ already exists with type ‘LONG’.
Context:
Azure DevOps pipeline triggers: PRs and long-lived branches
Branch detection in SonarCloud is configured with the regex: ^main$|^develop$|^stage$|^release/.* (long-lived branches)
Current PR/branch build task uses SonarCloudPrepare@3 for both PRs and long-lived branches:
It appears that the pipeline is attempting to publish analysis results for the develop branch as a short-lived (PR) branch, but this branch already exists in SonarCloud as a long-lived branch.
We would like guidance on:
How to correctly configure the pipeline so that long-lived branches such as develop are always treated as LONG.
Any recommended changes to SonarCloud settings or Azure DevOps tasks to prevent this error.
Best practices for PR vs long-lived branch analysis in SonarCloud.
We would greatly appreciate your assistance in resolving this issue.
Throwing this into regex101.com, it seems to be invalid. You just need to escape the /
^main$|^develop$|^stage$|^release\/.*
Once the regex is valid, you should be able to reanalyze as a long-lived branch.
Generally you analyze a PR when you… raise a PR, and get issues only on the code changed in the PR. However if you want to know the overall health of a branch, including “old” code (overall code) you’ll want a long-lived branch.
This works fine on every SonarCloud project apart from 1, where the pipeline builds are failing with an error. The weird thing is some of the release branches are set as long life branches and some of them are trying to be created as short life branches
The error message we are getting from the pipelines is:
##[error][ERROR] SonarQube Cloud: Error while executing task Publish: Task failed with status FAILED, Error message: Invalid branch type 'SHORT'. Branch 'releases/system-text-json-vulnerability-fix' already exists with type 'LONG'.
##[error]Task failed with status FAILED, Error message: Invalid branch type 'SHORT'. Branch 'releases/system-text-json-vulnerability-fix' already exists with type 'LONG'.
So firstly it shouldn’t be considered as short life branch and secondly there doesn’t seem to be a long life branch already existing for it!
We pushed a change that should fix the branch type detection on the first analysis of a branch. Since the branch type cannot be changed after the branch creation, you will first need to remove the branch in your project’s “Branches” page, then re-run an analysis on the branch.
Please let us know if that solves the issue for you.
Thank you