Invalid branch type 'SHORT'. Branch 'develop' already exists with type 'LONG'

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:
    - task: SonarCloudPrepare@3
      inputs:
        SonarQube: 'SonarQube Cloud'
        organization: 'gbsintegrations'
        scannerMode: 'dotnet'
        projectKey: 'GBSIntegrations_Thesis.EnrolmentUpdate'
        projectName: 'Thesis.EnrolmentUpdate'
        extraProperties: |
          sonar.cs.opencover.reportsPaths=$(Agent.TempDirectory)/**/coverage.opencover.xml
          sonar.cs.vstest.reportsPaths=$(Agent.TempDirectory)/**/*.trx
          sonar.coverage.exclusions=**/*Tests.cs,**/Tests/**,**/*Test.cs
          sonar.exclusions=**/bin/**,**/obj/**,**/*.g.cs
          sonar.verbose=true

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:

  1. How to correctly configure the pipeline so that long-lived branches such as develop are always treated as LONG.
  2. Any recommended changes to SonarCloud settings or Azure DevOps tasks to prevent this error.
  3. Best practices for PR vs long-lived branch analysis in SonarCloud.

We would greatly appreciate your assistance in resolving this issue.

Hey there.

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.

Let me try this also! The same expression I mentioned earlier was working fine till Thursday.

what should be the correct Regex?

Hey @averma3

I mentioned it here.

In fact, with both your regex and the original regex, the branch is picked up as long-lived.

Can you share where you’ve set the long-lived branch pattern? Feel free to share a screenshot.

We have a similar issue to this also, we use a global regex pattern for the whole of our organisation:

^(main|master|develop|(releases/.+))$

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!

1 Like

Exactly same issue, we are getting.

Thanks y’all. Hold tight — I’ve flagged this for the team.

2 Likes

Here are some of the analysis IDs of failing scans if you need them:

AZnDVuhE_HtOImR52Ryq
AZnDTxA4UFgVQrOwFaDg
AZnDQRhnankS6ulj4afZ

@Colin @Colin_M Could you please provide an update here?

Any Updates??

Hey team,

We are investigating, and I will update you ASAP as we know more.

We can reproduce the issue and are working on a fix!

Hi Colin,

Do you have a rough ETA on a fix? This is starting to affect more projects and become a blocker for us.

Hello,

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

What Long-Lived RegEx Pattern we should use?
can we use ^(master|main|develop|stage)$ ?

Yes that is correct, but that won’t include release/* branches you mentioned in your first posts.

Can confirm this is now working, just got to go through and delete all the short life branches now!

Thank you.

2 Likes