-
-
Notifications
You must be signed in to change notification settings - Fork 534
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Analysis fails with exception when project not created yet in Sonarqube #1
Comments
Can you confirm the following for me please:
I suspect this is an oversight in how I've implemented parameter validation and branch configuration, but want to check there's nothing odd being injected by other plugins, or provided by SonarQube's core. |
I'm using Sonarqube 7.6 with plugins:
|
I was about to report the same issue. Tested with Dockerized SonarQube versions 7.4 and 7.7, and 1.1.0-SNAPSHOT (latest commit 409c4ad). Using SonarScanner for MSBuild 4.4.2 that is installed on local machine. 0 other plugins.
|
…fied SonarQube returns an empty branch list if the project doesn't already exist which results in an error being thrown telling the user to re-run the scan with no branch parameters set, even if no branch analysis parameters were specified. However, when a project is created through the Web interface, SonarQube automatically creates a default branch named `master` which the scanner picks up as the primary branch and targets if no other parameters are specified. This inconsistency means users can't have SonarQube automatically create projects, but have to use the Web interface to set-up any projects first. To make the setup consistent, the check for no branches existing is extended to also check if any of the branch or pull request parameters have also been specified. This way, if no branches exist but no branch or pull request parameters were specified then a `DefaultBranchConfiguration` instance is returned which points the analysis at the a default `master` branch which SonarQube will create.
SonarQube returns an empty branch list if the project doesn't already exist which results in an error being thrown telling the user to re-run the scan with no branch parameters set, even if no branch analysis parameters were specified. However, when a project is created through the Web interface, SonarQube automatically creates a default branch named `master` which the scanner picks up as the primary branch and targets if no other parameters are specified. This inconsistency means users can't have SonarQube automatically create projects, but have to use the Web interface to set-up any projects first. To make the setup consistent, the check for no branches existing is extended to also check if any of the branch or pull request parameters have also been specified. This way, if no branches exist but no branch or pull request parameters were specified then a `DefaultBranchConfiguration` instance is returned which points the analysis at the a default `master` branch which SonarQube will create.
The issue seems to be due to overly strict validation in the plugin, and different behavior in SonarQube's response when queried for branches for a project that doesn't exist versus a project that does exist but hasn't been scanned. The plugin had been thoroughly tested against existing projects created through the user interface, but not through the automatic creation method this issue is using. I've made a change on the bug/issue1 branch, are you able to build a snapshot and run it to confirm if this fixes your issue? If it does then I'll get the branch merged and a new release published. |
|
Tested bf15e51 changes with SQ 7.4 and 7.7, working fine if project doesn't exist and a branch is not specified. Works: Doesn't work if the project doesn't exists first, but branch is specified (same error as before): Specifying "master", which is the default, should not throw errors, right? This case should also be covered (branch and target same, project doesn't exist) Not completely sure how the official version works, but https://github.com/msanez/sonar-branch-community worked with all variants above. |
The plugin doesn't currently do any logic around checking branch names, so specifying either It would be possible to check whether I don't know how the official version does this so can't tell if we're being consistent, but the documentation seems to indicate the default branch is created as We'd therefore handle combinations of inputs on a 'missing' project in the following way:
Does this proposed approach follow what you're attempting @dejangeci? |
@mc1arke Looks good to me. Second opinion from @winterheart, @nixel2007? |
Could you get info about project existance before scan? I am a gitflow-guy, so most projects start analyze from develop branch. From table above I'll get an exception on first run |
As per my comments in CommunityBranchConfigurationLoader.java, without deviating from what SonarQube currently has documented (which is what I'm initially aiming for feature parity against), there isn't really a way of using something other than It is theoretically possible to identify a new project because the branch list (and therefore the default branch) is empty when the scanner runs, but there's then no idea about whether a user expected the current branch to be the main branch, unless we treat |
SonarQube returns an empty branch list if the project doesn't already exist, which results in an error being thrown telling the user to re-run the scan with no branch parameters set, even if no branch analysis parameters were specified. However, when a project is created through the Web interface, SonarQube automatically creates a default branch named `master` which the scanner picks up as the primary branch and targets if no other parameters are specified. This inconsistency means users can't have SonarQube automatically create projects, but have to use the Web interface to set-up any projects first. To make the setup consistent, the check for no branches existing is extended to also check if any of the branch parameters have also been specified. This way, if no branches exist but no branch parameters were specified then a `DefaultBranchConfiguration` instance is returned which points the analysis at the a default `master` branch which SonarQube will automatically create. Similarly, if no branches exist but a source branch of master is specified then a `DefaultBranchConfiguration` is also returned, providing a target branch either isn't specified or also points at master.
I've made updates to the previous bugfix branch to meet the specifications in the table above, with the extra caveat that the source branch must be the same as the target branch if the target branch has been specified. This works in my local testing with:
It would be nice if someone could build and run this branch locally with some of their own real-world projects to confirm it works as they expect. @nixel2007 If you would like to target a branch other than master as the default primary then please raise a separate issue, or a pull request. |
SonarQube returns an empty branch list if the project doesn't already exist, which results in an error being thrown telling the user to re-run the scan with no branch parameters set, even if no branch analysis parameters were specified. However, when a project is created through the Web interface, SonarQube automatically creates a default branch named `master` which the scanner picks up as the primary branch and targets if no other parameters are specified. This inconsistency means users can't have SonarQube automatically create projects, but have to use the Web interface to set-up any projects first. To make the setup consistent, the check for no branches existing is extended to also check if any of the branch parameters have also been specified. This way, if no branches exist but no branch parameters were specified then a `DefaultBranchConfiguration` instance is returned which points the analysis at the a default `master` branch which SonarQube will automatically create. Similarly, if no branches exist but a source branch of master is specified then a `DefaultBranchConfiguration` is also returned, providing a target branch either isn't specified or also points at master.
Fix released in version 1.0.1 |
Would it be possible to reopen the issue? Our problem resembles the situation that @nixel2007 described for the case of Git Flow, but comes from a different side. The analysis is triggered by Jenkins pipelines. The pipelines pass the branch name as the properties to SonarQube. And when the project does not exist in SonarQube, the analysis fails, so does the pipeline and the build is broken. Of course, Jenkins can't know whether a project already exists in SonarQube, so it hardly can be blamed. In our case this becomes a show stopper as everyone can imagine. We have many small repositories, we use Git Flow and our team decided to set up an own SonarQube instance from scratch (since we want to stop sharing a SonarQube instance used by another team). And because we are starting from scratch, we wanted to try the latest LTS, so we gave 7.9.1 a chance. We used an older SonarQube before (7.6, to be precise). The older version created a project without asking and with no problems, so we were happy. But it is practically unbearable to create the projects manually in the UI. Because of Git Flow, it is not even a one-shot situation, but any new project (which is quite often) requires an annoying manual action. If the plugin created a new project as the older SonarQube version did, we would be happy again. If it is not possible, we have quite few options, if not counting the unprobable one of getting a better SonarQube edition: either reverting back to the no-fuss older version, or maybe the Jenkins pipeline could attempt to create the project always before the analysis. It seems possible with the Web API. But such a solution looks really awful, doesn't it? |
@pdolezal whilst I agree with you on this, SONAR-11155 is actually the blocker here given I've initially aimed to match the documented SonarQube parameters, and there's options in SonarQube for specifying the default branch name. If SonarSource don't provide any option for resolving this in the near future then I'm happy to add one to this plugin, but I'm aiming for feature parity rather than additional features in the early releases. |
@mc1arke I just run into this issue. Apparently this problem was fixed in Sonar 8.0 but even though I'm using 8.3.1 I still get this error when setting -Dsonar.branch.name and running the analysis for a new project:
|
@mc1arke Also I have the same issue. |
This was only fixed in 1.4.0 of the plugin. If you're still facing an issue when using the correct version then you'll need to provide full replication steps. |
@mc1arke Also I have the same issue.
|
See https://github.com/mc1arke/sonarqube-community-branch-plugin/releases/tag/1.4.0 - 1.4.0 only supports Sonarqube 8.1. The change that introduced the ability that allows branches to be created independently is not backwards compatible with 7.9 so cannot be cherry-picked into that release of the plugin. |
thank you |
@mc1arke sorry for asking on closed issue: but is it possible to use LTS 7.9 with 1.3.2 of the plugin? |
Hello.
I'm trying to test sources with command:
But on new projects (that not yet created in Sonarqube) I've got exception:
I have only one branch master and not passing any
-Dsonar.branch.*
to default command. How can I bypass this error?The text was updated successfully, but these errors were encountered: