Not getting analysis for merge-requests with gitlab-runner

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
    SonarQube 8.3.1-DE
  • what are you trying to achieve
    Analysis of multi-level Android project with Gitlab-Runner
  • what have you tried so far to achieve this
    Set values for gitlab host API
    Merge-request decoration stopped after upgrade from 8.1-DE
    image

Hi, You need to go to the admin settings to configure the GitLab ALM binding (with the gitlab api endpoint + token). You need to be a SonarQube admin to do that.

The main issue here is that it was already setup when we were running 8.1-DE but the upgrade broke all SCM connections (both github and gitlab)

What do you get in the ALM admin settings ?

Screen shot attached

Ok thanks, and what do you have at project level ? (Project Settings -> General Settings -> Pull Request Decoration). Is GitLab selected here?

Also, please have a look at the server’s logs, and see if you can see some error message when the decoration fail (should be in web.log or ce.log file).

In answer to the Project Settings -> General Settings -> Pull Request Decoration, it is set for GitLab, but there is a project ID in use (the info button for that field explains this is not needed if GitLab CI is being used, which is so. I reset the project ID to blank in this case.

I did note errors in the ce.log during pull-request decoration activity. A portion of the log is attached.cubi-analysis-failed.log (12.7 KB)

After making a minor change to the project Pull Request Decoration setting (removed possibly stale project ID), I was able to make a run without crashing the server thread.

I am still getting incorrect results from PR Decoration after setting change. Partial log result shows:

2020.06.12 09:50:26 INFO  ce[AXKn8AhrNDndQmMjymND][o.s.c.t.s.ComputationStepExecutor] Trigger refresh of Portfolios and Applications | status=SUCCESS | time=0ms
2020.06.12 09:50:26 INFO  ce[AXKn8AhrNDndQmMjymND][o.s.c.t.p.a.p.PostProjectAnalysisTasksExecutor] Webhooks | globalWebhooks=0 | projectWebhooks=0 | status=SUCCESS | time=2ms
2020.06.12 09:50:26 ERROR ce[AXKn8AhrNDndQmMjymND][c.s.C.D.D.B] Configuration is incomplete: GitlabPrSettings{instanceUrl='https://git.company.com/api/v4', token='********************', projectId=null, projectUrl=null, prId=2111}
2020.06.12 09:50:26 INFO  ce[AXKn8AhrNDndQmMjymND][o.s.c.t.p.a.p.PostProjectAnalysisTasksExecutor] Pull Request decoration | status=SUCCESS | time=8ms

The portion of the gitlab-runner yaml is for Merge Requests:

SonarQube analysis:
  stage: quality
  # We annotate only merge requests here. This job is to have merge requests decorated in GitLab.
  # There is a CI_MERGE_REQUEST_IID parameter for merge_requests always. We set sonarOptions here for a merge request only.
  script:
    - echo ${CI_MERGE_REQUEST_IID}
    - |
      sonarOptions="-Dsonar.pullrequest.branch=${CI_MERGE_REQUEST_TARGET_BRANCH_NAME} -Dsonar.pullrequest.base=${CI_MERGE_REQUEST_SOURCE_BRANCH_NAME} -Dsonar.pullrequest.key=${CI_MERGE_REQUEST_IID}" && \
      ./gradlew --parallel build -x test ${sonarOptions} sonarqube
  only:
    - merge_requests
  when: manual
  allow_failure: false

and for develop branch only:

SonarQube develop branch analysis:
  stage: triggers
  # We annotate develop branch here only.
  # This job is for sending continuous analysis to SonarQube, so we will see progress of fixing static analysis issues.
  script:
    # We dont need SonarQube to run each hour for scheduled pipeline with MONKEY_TEST parameter
    - |
      sonarOptions="-Dsonar.branch.name=${CI_COMMIT_BRANCH}" && \
      ./gradlew --parallel build -x test ${sonarOptions} sonarqube
  only:
    - develop

and we expect it will be including settings from build.gradle:

sonarqube {
    androidVariant 'debug'

    properties {
        property "sonar.sourceEncoding", "UTF-8"
        property "sonar.verbose", true
        property "sonar.host.url", "https://sonarqube.example.com"
        property "sonar.login", "REDACTED"
        property "sonar.branch.name", "develop"
        property "sonar.projectName", "Atom (Streamer device)"
        property "sonar.projectKey", "cubi-android-example-app"
        property "sonar.sourceEncoding", "UTF-8"
        property "sonar.projectVersion", getAtomVersionName()
        property "sonar.issuesReport.html.enable", "true"
        property "sonar.issuesReport.console.enable", "true"
        property "sonar.verbose", "true"

        property "detekt.sonar.kotlin.config.path", "quality/detekt/detekt-config.yml"

        // no code coverage in Atom yet
        // property "sonar.coverage.jacoco.xmlReportPaths", findAllReports()
        // property "sonar.java.coveragePlugin", "jacoco"
  }
}

Hi, you only need to provide SONAR_HOST_URL and SONAR_TOKEN. By providing sonar.pullrequest.branch or sonar.pullrequest.key, you are disabling the auto-detection of env variable.

Unfortunately, things got worse when I limited parameter settings. I discovered in the logs that settings in the SonarQube instance interfered with auto-detected settings:

2020.06.12 09:50:26 INFO  ce[AXKn8AhrNDndQmMjymND][o.s.c.t.s.ComputationStepExecutor] Trigger refresh of Portfolios and Applications | status=SUCCESS | time=0ms
2020.06.12 09:50:26 INFO  ce[AXKn8AhrNDndQmMjymND][o.s.c.t.p.a.p.PostProjectAnalysisTasksExecutor] Webhooks | globalWebhooks=0 | projectWebhooks=0 | status=SUCCESS | time=2ms
2020.06.12 09:50:26 ERROR ce[AXKn8AhrNDndQmMjymND][c.s.C.D.D.B] Configuration is incomplete: GitlabPrSettings{instanceUrl='https://git.cubiware.com/api/v4', token='********************', projectId=null, projectUrl=null, prId=2111}
2020.06.12 09:50:26 INFO  ce[AXKn8AhrNDndQmMjymND][o.s.c.t.p.a.p.PostProjectAnalysisTasksExecutor] Pull Request decoration | status=SUCCESS | time=8ms

I have looked at the analysis results for this job and I still see the error message:

ProjectId and ProjectUrl should be auto-detected from env variable in the runner. Do you have the log of the runner please?

I’ve attached relevant portion of the logcubi-analysis-failed.log (12.7 KB)