Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sonar analysis using multiple git branches in Jenkins

I have setup Jenkins to automatically build several git branches of my project. The build also triggers Sonar analysis, as a post-build action.

The problem is that all branches point to the same Sonar project. I know that there is a sonar.branch property. Is it possible to have Jenkins automatically set sonar.branch property to the current git branch being built (without having to change project's pom.xml)?

like image 524
spyk Avatar asked Mar 24 '13 08:03

spyk


2 Answers

You can try adding -Dsonar.branch.name=something in the field MAVEN_OPTS in jenkins post-build action (Advanced configuration).

I don't know how to resolve something, since I don't know how you configure your jenkins job... but it will probably be something like $git.branch.

I didn't try, so i'm not sure it will work.

In a Jenkins multi-branch pipeline, the variable is BRANCH_NAME.

P.S. While reading your question it's difficult to say if you are using maven or not to trigger sonar. If you are not using maven: there is a project properties field in the Jenkins config where you can define sonar.branch.

like image 181
ben75 Avatar answered Sep 23 '22 01:09

ben75


This should work

mvn sonar:sonar -U -Dsonar.branch.name=$BRANCH_NAME
like image 45
Gnani Avatar answered Sep 23 '22 01:09

Gnani