Sonarqube branch detection

Hello,
I’m using Sonarqube Developer Edition 9.2.4.
I’ve been reading the docs, from what I understand sonarqube can’t analyze more than one branch unless the jenkins project is a multibranch pipeline project and the proper plugins are installed right?
The problem is a lot of currently running projects are NOT multibranch.
When executing sh "env" inside my pipeline I get the environment variable
image
I was wondering if there was a way to “instantiate” the variable so that Sonarqube detects it as well, because as it stand, my JSON payload is :

"branch": {
    "name": "master",
    "type": "BRANCH",
    "isMain": true,
    "url": "http://localhost:9000/dashboard?id=projectkey
  }

Even when I am running the Jenkinsfile from the devops branch.
Any workaround or explanation please? I feel like I am missing something.
Thanks,

Hey there.

While this works best (and without any additional configuration) in multibranch pipelines, if an environment variable is available with the branch name you can pass this to the sonar.branch.name analysis parameter and it will be used during analysis to send the analysis to a specific branch.

1 Like

Thank you Mr Colin, that seems to have solved the issue, I even tried with custom name “master” to test it out and it didn’t create a duplicate, which is nice.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.