Skip to content
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

SQ 10.3.0-community + plugin 1.18.0 got error "No branch exists in Sonarqube with the name" #909

Closed
fourirakbar opened this issue May 10, 2024 · 5 comments · Fixed by #950
Labels
bug Something isn't working

Comments

@fourirakbar
Copy link

fourirakbar commented May 10, 2024

Describe the bug
We submit a PR to a branch that doesn't exist in SQ (but already exists in the GitHub repo). For example, in SQ only the "main" branch is listed, while we submit a PR to the "develop" branch. Then, we will get an error "No branch exists in Sonarqube with the name."

Previously, we used Sonarqube version 9.3.0-community and plugin 1.12.0, everything ran normally and there was no error like this.

To Reproduce

  1. Make a PR to a non-existing branch in SQ, let's say to branch "develop"

Expected behavior

  1. Non-existing branch (develop) is created automatically in SQ
  2. There is no error "No branch exists in Sonarqube with the name"

Software Versions
SonarQube Version: 10.3.0-community using helm chart
Plugin Version: 1.18.0
Sonar maven scanner version: 3.11.0.3922

Additional context
My code uses Java Spring (Maven). Meanwhile, I can solve this by adding <sonar.branch.name>develop</sonar.branch.name> in the pom.xml. The effect is that the "develop" branch will appear in SQ. Then I must remove <sonar.branch.name>develop</sonar.branch.name> from the pom.xml and make the PR again. This is quite inconvenient for us, because with the previous version I did not have to do this.

My problem might be similar to #854, but I still don't quite understand how to fix it.

@fourirakbar fourirakbar added the bug Something isn't working label May 10, 2024
@fourirakbar fourirakbar changed the title SQ 10.3.0-community + plugin 1.18.0 got errpr "No branch exists in Sonarqube with the name" SQ 10.3.0-community + plugin 1.18.0 got error "No branch exists in Sonarqube with the name" May 10, 2024
@hballangan-mdsol
Copy link

hballangan-mdsol commented May 22, 2024

@mc1arke having the same error. I would add that this issue raises more concerns as it's affecting a lot of repos doing lots of release and non-main branches. In the original feature we only have to address the issue once during project creation, which is easily mitigated with proper documentation and by following instructions on how to properly create a project. But now we will have to modify CI behavior and also address all new issues on creating new branch scan for each non-main/release branch.

Our CI before the change:

name: CI - Test Automation
on:
  workflow_dispatch:
  push:             
    branches:
      - develop
  pull_request:

Our CI so that we don't get affected by the new feature (we have to remove on push develop):

name: CI - Test Automation
on:
  workflow_dispatch:
  pull_request:

For us to create non-main branches, we now have to remove and let it run on all branches, which is a lot of wasted resources since we are already running on PR and also it will create a lot of useless branches (since we only need main, or release). Our last option is to totally disable code analysis if the target branch is NOT develop which is not ideal since we also want to analyse some custom or release branches OR add continue-on-error: true on Code analysis which will ignore underlying issues.

Now I understand that the new feature added was to prevent errors at the start of code analysis if no main branch exists, but that error doesn't happen if the project has already been created and we just want to merge to custom branch. Maybe a workaround for this is to only reject on project creation (OR if target branch is main/develop/master) and accept PR analysis if project already exists. Why I suggest this is that we never encountered any error when project already exists.

@hballangan-mdsol
Copy link

hballangan-mdsol commented May 22, 2024

For those encountering this issue on Github actions, a workaround is to add workflow dispatch:

on:
  workflow_dispatch:

And manually trigger the Code Analysis Github Action on the non-main branch. You have to do this for all new non-main feature/release branch.

@maicaballangan
Copy link

Found that the feature for sonarqube includes autocreation of branches(see provision github projects with ease) when using the github action. So it is going against the direction of the upgrade if the community pull request is doing the opposite and restricting autocreation of branches

@visu-suganya
Copy link

@mc1arke
Thanks for your effort.
We had already configured community sonar branch plugin with -Dsonar.pullRequest.base=develop property in 9.9.
Then upgraded to 10.3 with branch plugin. But now pullRequest.base property is not working, Im getting errors from all the CIs wherever configured with this before.

Please let us know how to do workaround when using in github actions using sonarqube-scan-action and in circleci docker image.

@mc1arke
Copy link
Owner

mc1arke commented Aug 11, 2024

Non-existing branch (develop) is created automatically in SQ

This is where the problem lies: the plugin (or Sonarqube) doesn't know what's on that branch, so can't realistically report new/changed issues.

Found that the feature for sonarqube includes autocreation of branches(see provision github projects with ease) when using the github action. So it is going against the direction of the upgrade if the community pull request is doing the opposite and restricting autocreation of branches

I don't think the release note you've mentioned in your comment indicates anything about automatic creation of branches - only that Sonarqube will automatically configure project details (branch name and pull request decoration) for you.

If you can show evidence that demonstrates automatic scanning of a target branches on submissions of a scan then I'll happily investigate how to make the plugin work in the same way, but the current implementation is as it is to prevent misleading scans being presented to users.

Then upgraded to 10.3 with branch plugin. But now pullRequest.base property is not working, Im getting errors from all the CIs wherever configured with this before.

I'm presuming you're getting an error stating that No branch exists in Sonarqube with the name ... when using sonar.pullrequest.base, which is intended if you haven't scanned the target branch.

@mc1arke mc1arke closed this as completed Aug 11, 2024
@mc1arke mc1arke reopened this Aug 17, 2024
mc1arke added a commit that referenced this issue Aug 18, 2024
The resolution of Pull Request details currently uses the project
default branch when a pull request is analysed without specifying a
target branch. However, when a target branch is specified, the plugin
expects that branch to exist and throws an exception if the target
branch is not found. To overcome this, the target branch is being
resolved to the default branch where no target branch is specified or
the requested target branch does not exist. As the API used to gather
branch information does not return PULL_REQUEST details, the result of
this searching is that a pull request will either target a branch from
the main branch, or target the main branch, there is no further nesting
or pull requests and branches.
dimitri-segard added a commit to paypay/sonarqube-community-branch-plugin that referenced this issue Sep 6, 2024
… not exist (#15)

The resolution of Pull Request details currently uses the project
default branch when a pull request is analysed without specifying a
target branch. However, when a target branch is specified, the plugin
expects that branch to exist and throws an exception if the target
branch is not found. To overcome this, the target branch is being
resolved to the default branch where no target branch is specified or
the requested target branch does not exist. As the API used to gather
branch information does not return PULL_REQUEST details, the result of
this searching is that a pull request will either target a branch from
the main branch, or target the main branch, there is no further nesting
or pull requests and branches.

Co-authored-by: Michael Clarke <michael.m.clarke@gmail.com>
mc1arke added a commit that referenced this issue Sep 6, 2024
The resolution of Pull Request details currently uses the project
default branch when a pull request is analysed without specifying a
target branch. However, when a target branch is specified, the plugin
expects that branch to exist and throws an exception if the target
branch is not found. To overcome this, the target branch is being
resolved to the default branch where no target branch is specified or
the requested target branch does not exist. As the API used to gather
branch information does not return PULL_REQUEST details, the result of
this searching is that a pull request will either target a branch from
the main branch, or target the main branch, there is no further nesting
or pull requests and branches.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
5 participants