Can't select GitLab from list of Providers for Pull Requests

Although my project has been bound successfully to my GitLab project, I cannot select GitLab from the list of providers.

What I’ve tried so far:
-Checking permissions for the GitLab access token (currently has: API, read_repo, write_repo)

Hey there.

If your project is bound to a Gitlab repo, you don’t need to do anything else.

This:

Is a very old (poorly described) setting, that should not be used outside of very specific Azure DevOps related contexts.

Without selecting anythiung here, is the integration working well with Gitlab?

Hi there,
It’s bound correctly, but nothing shows up in the merge requests section on SonarQube and nothing shows up in GitLab about the scans.

It sounds like you aren’t actually analyzing the PRs. Can you share how you’ve set up your CI to run the analysis? If you’re using Gitlab CI, for example, that means sharing your Gitlab CI YML file.

# ------------------ FRONTEND SCAN ------------------ #
sonarqube_scan_frontend:
  stage: test
  image: sonarsource/sonar-scanner-cli:latest
  tags:
    - saas-linux-xlarge-amd64
  variables:
    SONAR_TOKEN: $SONAR_TOKEN_FRONTEND
  script:
    - cd frontend
    - sonar-scanner -Dsonar.token=$SONAR_TOKEN -Dsonar.host.url="https://sonarcloud.io" -Dsonar.exclusions="**/*.css"

# ------------------ BACKEND SCAN ------------------ #
sonarqube_scan_backend:
  stage: test
  image: mcr.microsoft.com/dotnet/sdk:8.0
  tags:
    - saas-linux-xlarge-amd64
  variables:
    SONAR_TOKEN: $SONAR_TOKEN_BACKEND
  script:
    # Install Java for SonarScanner
    - apt-get update && apt-get install -y openjdk-17-jre
    - export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
    - export PATH=$JAVA_HOME/bin:$PATH
    
    # Install SonarScanner
    - dotnet tool install --global dotnet-sonarscanner
    - export PATH="$PATH:/root/.dotnet/tools"

    # Navigate to the correct directory for the project and properties file
    - cd Neo/Neo

    - dotnet restore Neo.csproj
    - dotnet restore ../Common/Neo.Common.csproj

    # Begin SonarQube Scan
    - dotnet-sonarscanner begin /k:"project-neo_BE" /o:"project-neo" /d:sonar.token=$SONAR_TOKEN /d:sonar.scanner.skipJreProvisioning=true

    # Build the project
    - dotnet build Neo.csproj --no-restore
    - dotnet build ../Common/Neo.Common.csproj --no-restore
    
    # End SonarQube Scan (with token to match the begin step)
    - dotnet-sonarscanner end /d:sonar.token=$SONAR_TOKEN

Do you have a section where you define on which types of jobs the pipeline should run?

This typically looks like this

  only:
    - merge_requests
    - master
    - develop

or

  rules:
    - if: $CI_COMMIT_BRANCH == 'main'
    - if: $CI_COMMIT_BRANCH == 'develop'
    - if: $CI_PIPELINE_SOURCE == 'merge_request_event'
workflow:
  rules:
    - if: $CI_COMMIT_BRANCH == "sbx" || $CI_COMMIT_BRANCH == "development" || $CI_COMMIT_BRANCH == "qa" || $CI_COMMIT_BRANCH == "uat" || $CI_COMMIT_BRANCH == "sharedservices"
      variables:
        CICD_ENVIRONMENT_NAME: $CI_COMMIT_BRANCH
    - if: '$CI_COMMIT_TAG =~ /^release-[0-9]+\.[0-9]+\.[0-9]+$/'
      variables:
        CICD_ENVIRONMENT_NAME: "prod"

Well, it looks like none of those rules would run the job on a MR build. You should add a rule like this:

    - if: $CI_PIPELINE_SOURCE == 'merge_request_event'

Sorry for the delay, but unfortunately that still didn’t work.

sonarqube_scan_frontend:
  stage: test
  image: sonarsource/sonar-scanner-cli:latest
  tags:
    - saas-linux-xlarge-amd64
  variables:
    SONAR_TOKEN: $SONAR_TOKEN_FRONTEND
  script:
    - cd frontend
    - sonar-scanner -Dsonar.token=$SONAR_TOKEN -Dsonar.host.url="https://sonarcloud.io" -Dsonar.exclusions="**/*.css"
  rules:
    - changes:
      - "frontend/**/*"
    - if: $CI_PIPELINE_SOURCE == 'merge_request_event'

In that case I’d suggest you share the logs from your Gitlab MR pipeline – to see if SQ analysis is running at all, and if it is, why it isn’t identifying it as a MR analysis.

It might also be because oft his:

In your tests, are you changing code in the frontend directory?