Short-lived branch analysis not working -> Project not found

Hello

We are writing to ask about the project not found error on our short-lived branch analysis. We using sonarcloud for a group project at the university and come across a problem for our short-lived branch. Our setup is as follows:
- CI and Git host → gitlab selfhosted by the university
- Sonarcloud setup → Because gitlab is selfhosted, we had to follow the setup for non-integrated build environment
- Language → Java 17
- Build Tool → Maven
- Sonar Maven Plugin Version → 3.9.1.2184
- Gitlab CI:

image: maven:3.9.0-amazoncorretto-17

stages:
  - code_style_check
  - unit_test
  - code_quality_analysis

variables:
  MAVEN_CLI_OPTS: >-
    -Dsonar.login=$SONAR_TOKEN
    -Dsonar.host.url=https://sonarcloud.io
    -Dsonar.organization=xx
    -Dsonar.projectKey=xx_xx
    -Dsonar.branch.name=Pipeline_Fix
    -Dsonar.branch.target=main -Dsonar.verbose=true -X

code_style_check:
  stage: code_style_check
  script:
    - mvn checkstyle:check

unit_test:
  stage: unit_test
  script:
    - mvn test

code_quality_analysis:
  stage: code_quality_analysis
  script:
    - 'mvn verify sonar:sonar $MAVEN_CLI_OPTS'

Our gitflow consist of a main branch and shortlived feature branches.
The main branch analysis always works without any problems, but the shortlived branch always crashes when the analysis should be uploaded. We tested the branch analysis also locally and it worked, but on the CI it crashes.
For testing purpose we hardcoded the branch.name (pipeline runs on the correct branch). The organization and projectKey are redacted also the stuff in the log message.
Here are the detailled error message:

[INFO] 15:38:45.700 Analysis report generated in /builds/x/target/sonar/scanner-report
[DEBUG] 15:38:45.700 Upload report
[DEBUG] 15:38:45.783 POST 404 https://sonarcloud.io/api/ce/submit?organization=xx&projectKey=xx_xx&projectName=xxx&characteristic=branch%3DPipeline_Fix&characteristic=branchType%3DSHORT | time=83ms
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  24.707 s
[INFO] Finished at: 2023-04-07T15:38:45Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar (default-cli) on project x: Project not found. Please check the 'sonar.projectKey' and 'sonar.organization' properties, the 'SONAR_TOKEN' environment variable, or contact the project administrator -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar (default-cli) on project x: Project not found. Please check the 'sonar.projectKey' and 'sonar.organization' properties, the 'SONAR_TOKEN' environment variable, or contact the project administrator

We would like to know where the error lies.
Thank you for your help in advance.

Hi,

Welcome to the community!

I think the error message is key here:

If you’re sure the project key and organization are correct, you should double check the SONAR_TOKEN value set in your environment.

 
HTH,
Ann

Hi,

I am also concerned with this issue. We have been integrated (operating as a business) for years, with valid project key and company, only for our build pipelines to start failing on the very same error since Thursday ~12:00PM UK time. I also doubt the our token is invalid since it was recently refreshed and the service connection is verified through Azure DevOps.

I see there are no issues reported on the Sonas Status page either.

Regards,

Brian

Hi Brian,

Please create a new thread and provide your full analysis log.

 
Thx,
Ann

Hi,

The problem was that gitlab was incorrectly configured.
I checked the ‘sonar.projectKey’ , ‘sonar.organization’ and the ‘SONAR_TOKEN’ and all these things where correct.
However I had incorrectly checked the “protected variable” flag in gitlab (See picture Info), which only expose the variable to a protected branch. In our project ‘main’ is protected but all the feature branches not, so when the pipeline was run the ‘SONAR_TOKEN’ was not available.

1 Like

Oddly, this was resolved for us by re-generating the token.

1 Like

Hi @BigChungus,

Thanks so much for sharing your solution! I know this will help others in the future.

 
:smiley:
Ann

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.