The problem
We are using GitLab Pipelines to scan our code on every commit. This worked for the past years, however recently we started having problems. When we perform a code analysis for a dotnet application on a branch other than develop, we get the following error:
ERROR: Project not found. Please check the ‘sonar.projectKey’ and ‘sonar.organization’ properties, the ‘SONAR_TOKEN’ environment variable, or contact the project administrator to check the permissions of the user the token belongs to
ERROR:
The SonarScanner did not complete successfully
However, if we run a code analysis on the develop branch the analysis succeeds.
Environment variables
I checked the environment variables:
Variable | Value | Environment | Protected |
---|---|---|---|
SONAR_HOST | https://sonarcloud.io/ | All | No |
SONAR_TOKEN | [redacted] | All | No |
SONAR_ORGANIZATION | [redacted] | All | No |
SONAR_PROJECT_KEY | [redacted] | All | No |
So the same env variables are being used on all branches.
Command
We are using the following commands to run the analysis:
dotnet-sonarscanner begin /n:$solutionName /key:$projectKey /v:"$version" /d:sonar.token="$SONAR_TOKEN" /d:sonar.host.url="$SONAR_HOST" /d:sonar.cs.opencover.reportsPaths="test/**/coverage.opencover.xml" /d:sonar.coverage.exclusions="$coverageExclusions" $sonarParams /o:$SONAR_ORGANIZATION
dotnet build
dotnet-sonarscanner end /d:sonar.token=$SONAR_TOKEN
Frontend scan
We don’t have this problem with our frontend scans (vuetify project). We use this command for the scan:
sonar-scanner -Dsonar.organization=$SONAR_ORGANIZATION -Dsonar.projectKey=$SONAR_PROJECT_KEY -Dsonar.token=$SONAR_TOKEN -Dsonar.host.url=$SONAR_HOST -Dsonar.sources=$SONAR_SOURCES -Dsonar.tests=$SONAR_TESTS -Dsonar.javascript.lcov.reportPaths=$SONAR_JAVASCRIPT_LCOV_REPORTPATHS -Dsonar.testExecutionReportPaths=$SONAR_TEST_EXECUTION_REPORTPATHS -Dsonar.test.inclusions=$SONAR_TEST_INCLUSIONS -Dsonar.qualitygate.wait=true
The enviroment variables used are the same as the dotnet scan.
Summary
So suddenly code analysis of dotnet applications on branches other than develop stopped working. Does anybody have an idea what can cause this?
Thanks in advance!