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

Sonar CNES Report Generation Fails When Utilizing Jenkins Global Env Var #340

Open
alexandrasims opened this issue Nov 28, 2022 · 0 comments

Comments

@alexandrasims
Copy link

Encountering branch not found error when Sonar CNES report generation utilizes the BRANCH_NAME Jenkins global environment variable.

Environment:
Sonar CNES Report version 4.1.1 with SonarQube server 9.4 (a recommended workaround has been added to get these two versions to work together).

This error was found while using the following combination of services: Bitbucket, Jenkins, SonarQube w/ PR Decorations enabled, Sonar CNES Report tool and using the Jenkins BRANCH_NAME global env var for the --branch option.

i.e. java -jar <cnes-report-jar-file> -t <sonarqube-token> -s <sonarqube-url> -p <project-name> -b ${env.BRANCH_NAME}

Steps to Reproduce Error:

  1. SonarQube PR Decorations enabled and synced with Bitbucket
  2. PR opened in Bitbucket
  3. Bitbucket webhook prompts a build in Jenkins to start
  4. Jenkins global env var, BRANCH_NAME, pulls the PR branch name from Bitbucket (i.e. PR-25)
  5. CNES report tool tries to find this PR branch name in SonarQube
  6. CNES report tool throws error during Jenkins build saying that it cannot find this branch in SonarQube

And here is the actual error that results in Jenkins:

[Pipeline] sh
+ java -jar <cnes-report-jar-file> -t <sonarqube-token> -s <sonarqube-url> -b PR-25
SonarQube URL: <sonarqube-url>
SonarQube online: true
Detected SonarQube version: 9.4.0.54424
[ERROR] Not found error sent by SonarQube server (code 404, URL https://<sonarqube-url>/api/navigation/component?component=<project-name>&branch=PR-25, Error {"errors":[{"msg":"Component \u0027<project-name>\u0027 on branch \u0027PR-25\u0027 not found"}]}), please check cnesreport compatibility with your SonarQube server version.
[Pipeline] }

I've been thinking about how this could be resolved. It doesn't seem like Bitbucket nor Jenkins should change their naming system in this case. It also doesn't seem like SonarQube should change their naming system for PR branches since it doesn't look like their API provides any meaningful data for the Sonar CNES Report tool to use for a PR branch anyways.

In short, it seems like these PR branches may not be useful for generating a CNES report; as such, I thought it would make sense to reach out here to see if there was a way for PR branches specified in the --branch option to be handled/ignored by the Sonar CNES Report tool?

Thanks in advance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant