How to get sonar.scm.url?

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension) : * 7.9.1
  • what are you trying to achieve : Like to map SCM URL with sonar key and vise-versa
  • what have you tried so far to achieve this : Explored Api’s and some searching

Welcome :slight_smile:

I guess you’re looking for sonar.links.scm which is <scm><url> for Maven
See api/project_links/search

Gilbert

I am looking for on Java projects

sonar.links.scm is a property for setting the link to sources on Sonarqube project dashboard.
If you want to get this property from a Sonarqube project, you may use the web api
api/project_links/search
For Maven builds this property may be set via pom.xml and <scm><url>.

Hi ,

I am empty array as an response for api/project_links/search api.

Is they any alternative here

-Prashanth

Hi,

getting an empty result means there are no sonar.links.* properties set for
this Sonarqube project.

Gilbert

Yes, Is there a way to get it .

We are using sonarqube github app , but not sure how the app is identify the sonar key from github.

I appreciate your help here.

-Prashanth

Don’t understand what the question is !?
We only know you use Sonarqube 7.9.1 (which edition ?) for analysing Java projects.
You need to provide more details about your build chain and workflow.
Usually the Sonarqube analysis runs as part of a build.
Do you use Github ?
What is your buildtool, Maven, Gradle … ?
Do you use a buildserver, e.g. Jenkins pipelines for your builds ?

You want to use a part of scm url as value for the sonar.projectKey property ?
If the scm url in your build is e.g. https://github.com/Foo/foobar the projectKey should be foobar ?

This might help to get you going
https://docs.sonarqube.org/latest/analysis/analysis-parameters/
https://docs.sonarqube.org/latest/analysis/scan/sonarscanner-for-maven/ if it’s a maven build
https://docs.sonarqube.org/latest/analysis/scan/sonarscanner-for-gradle/ if it’s a gradle build
https://docs.sonarqube.org/latest/analysis/scan/sonarscanner-for-jenkins/ if it runs in Jenkins

https://github.com/SonarSource/sonar-scanning-examples with examples for maven and gradle

1 Like