kicksticks
kicksticks

Reputation: 239

How to make the git branch name part of the SonarQube project name?

I'm using TFS as my scm, Jenkins, and SonarQube. I'm trying to run a build for my maven project, and I'd like to trigger SonarQube as well. I have everything working fine, but I'd like to add the name of the branch from TFS as part of the project key in SonarQube.

So, in my pom.xml file, I have the following line in my properties.

<sonar.projectKey>com:${env.GIT_BRANCH}</sonar.projectKey>

I then get this error:

"com.origin/master" is not a valid project or module key. Allowed characters are alphanumeric, '-', '_', '.' and ':', with at least one non-digit.

I was wondering if there's a way for me to parse this variable to get rid of the "origin/" so that I can make this a valid project key.

I can do mvn sonar:sonar -Dsonar.projectKey="com:%GIT_BRANCH:~7%" but I'm wondering if there's a way to do this having everything in the pom.xml file

EDIT: I'm building with Jenkins

Upvotes: 3

Views: 4648

Answers (1)

agabrys
agabrys

Reputation: 9116

You should use sonar.branch property.

See SonarQube Analysis Parameters.

Upvotes: 1

Related Questions