cathive / concourse-sonarqube-resource

performs SonarQube analyses and checks quality gates https://concourse-ci.org/ https://sonarqube.org/
Apache License 2.0
46 stars 49 forks source link

Set sonar.branch automatically from current Git branch #3

Closed headcr4sh closed 6 years ago

headcr4sh commented 7 years ago

branch-based analysis currently requires to set the branch param of the out action manually. It would be easier to determine the branch automatically (if desired by the user?) from the state of the checked out Git resoure (... IF we are dealing with a GIt resource that is...)

headcr4sh commented 6 years ago

sonar.branch has been deprecated since SonarQube 6.7. (see https://docs.sonarqube.org/display/SONAR/Analysis+Parameters)

The "developer edition" of SonarQube offers branch features, though. (The work in a different way, though and require a paid subscription of SonarQube) The new branch features require that a project must be analyzed without specifying a branch when performing the first scanner-run though, which is a bit unfortunate and might complicate things a bit when trying to do that automatically from within the concourse resource's out step.

pawel-sw commented 6 years ago

There is a new Branch Plugin for SonarQube Community Edition https://github.com/s-pw/sonar-branch-community. It has the same limitation that branch can't be set for the first scan I'll try to remove this limitation

headcr4sh commented 6 years ago

Sounds great. Once the "first scan issue" has been resolved with your plugin (nice work btw!!) this ticket can be re-opened / unblocked.

pawel-sw commented 6 years ago

The plugin now allows setting branch for the first use but it will only allow master for the first scan as short-lived branch scan depends on the existing project.

headcr4sh commented 6 years ago

sounds like a reasonable limitation to me, if you ask. Making the long-lived branch configurable would be nice-to-have, but seems to be a corner case. (I assume that most projects use master as their default branch nowadays...)

ghost commented 6 years ago

I just compiled it & placed it to appropriate place & restarted SonarQube. But do not know how to use it. also can not find any useful documentation on it's user guide, can you please direct me to the right way?

headcr4sh commented 6 years ago

@crsardar

I have not (yet) thought about how to implement this feature in detail.

I suppose, we will need another boolean flag (auto_detect_scm_branch) that can be configured as param to the out action of the resource.

If this boolean flag has been set to true, we will have to check if the directory which is to be analyzed by the sonar-scanner is a git, a hg, a svn,... repository. (I assume it's reasonable to start with a git implementation and skip the other VCS systems for now...)

... well... that's basically what has to be implemented. ;-)

knyomi commented 6 years ago

@headcr4sh I made this change to the community edition of branch over the weekend. It only works for Git repositories since that's what we needed it for. If anyone is interested in using it in it's current state, I'm happy to push my fork to a public repo. Else, I'll clean it up and factor for other SCM's and make a PR to the branch community repo.

headcr4sh commented 6 years ago

"only git" would be a great first step towards full-fledged branching-support, I think.

knyomi commented 6 years ago

I'll push it sometime this week.

headcr4sh commented 6 years ago

@knyomi I just pushed some changes that implement automatic branch detection in a way that I think might work out in conjunction with your SonarQube plugin (or the official SonarSource one,...).

If you think, that my solution needs improvement, feel free to open another issue / PR.

Looking forward to hearing from you.