GitLab CI Pipeline fails with default sonar yml file

I have set up a gitlabs account, set up a sonar account and tried to get sonar to scan my php app
As per the walk through I set up the CI/CD variables.
When the pipeline runs it gives errors:

NFO: Total time: 33.084s
INFO: Final Memory: 8M/61M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarScanner execution
ERROR: You must define the following mandatory properties for 'Unknown': sonar.projectKey, sonar.organization
ERROR: 
ERROR: Re-run SonarScanner using the -X switch to enable full debug logging.
Cleaning up file based variables
ERROR: Job failed: exit code 1

As there is no requirement or information on setting up those two variables in the Sonar documentation they are not setup.
Where do I get values for these and where do I set them up

THe yml file looks like:

variables:
  SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar"  # Defines the location of the analysis task cache
  GIT_DEPTH: "0"  # Tells git to fetch all the branches of the project, required by the analysis task
sonarcloud-check:
  image:
    name: sonarsource/sonar-scanner-cli:latest
    entrypoint: [""]
  cache:
    key: "${CI_JOB_NAME}"
    paths:
      - .sonar/cache
  script:
    - sonar-scanner
  only:
    - merge_requests
    - master
    - develop

Hello @Flugan,

This is probably because you did not see step 3 in the tutorial, this step mentions to commit a sonar-project.properties file into your repository which contains the missing properties. You can access this tutorial again by navigating to your project on SonarCloud and clicking on Administration > Analysis Method > With GitLab CI/CD Pipeline.

That being said I understand that you missed that step. It’s not very visible and it should be done before committing the changes in the .gitlab-ci.yml file. Here is a ticket we created to improve this behaviour.

1 Like