The project is created in our SonarCloud organization but no analysis has ran against it.
We setup a bitbucket-pipelines.yml to analyse master branch.
image: maven:3.5.2-jdk-8
pipelines:
default:
- step:
name: Build and run the SonarCloud Scanner
script:
- mvn --settings settings.xml -B compile org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.branch.name=$BITBUCKET_BRANCH -Dsonar.projectKey=$SONAR_ORGANIZATION_$BITBUCKET_REPO_SLUG -Dsonar.organization=$SONAR_ORGANIZATION -Dsonar.host.url=$SONAR_URL -Dsonar.login=$SONAR_TOKEN
The sonar-scanner show the following error:
[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.6.0.1398:sonar (default-cli) on project service-example: Project was never analyzed. A regular analysis is required before a branch analysis -> [Help 1]
This workflow was functional before.
Why is it defaulting to branch analysis instead of regular analysis for the master branch.
I ran some more tests, it appears that it works fine if I use the SonarCloud UI for the bitbucket integration to create the SonarCloud project and then run the analysis.
Can you echo $SONAR_ORGANIZATION_$BITBUCKET_REPO_SLUG (which you supply as the projectKey) during the Bitbucket Pipeline execution and post it here? It’s pretty strange that there is an underscore in it but in the logs it is resolved to ops-service-example which has no underscore at all:
[INFO] Load project settings for component key: 'ops-service-example'
@Michal_Duda you are correct $SONAR_ORGANIZATION_$BITBUCKET_REPO_SLUG is not being interpolated correctly as bash think that the variable name is $SONAR_ORGANIZATION_ and not $SONAR_ORGANIZATION (it interpolate as empty value).
So the project key is wrong.
Can we get a more descriptive message on this error?