Sonarcloud error when merge request

Hi Team,

we found an error on sonarcloud when merge requests scan gitlab.

Caused by: Error 404 on https://sonarcloud.io/api/alm_integration/show_pullrequest?project=xxxxx&pullrequestKey=1923 : {“errors”:[{“msg”:“Unable to find the pullrequest with key \xxx\xxx”}]}

this is branch in cicd

only:
- merge_requests
- develop

can anyone help me?

1 Like

@janos can help me?

I have a couple of questions to try to understand what’s going on:

  • What are the steps you take before this error appears?
  • Where exactly does this error appear?
  • If you go to your project in SonarCloud, navigate to the list of pull requests, do you see this pull request listed? (“pull request” is a term we use that’s equivalent to “merge request” on GitLab.) Also:
    • Do you see any other pull requests listed?
    • If you visit the url in your browser, do you get a successful response, or is it 404?

Based on the 404 error response, I suspect the pull request doesn’t exist on SonarCloud. Please confirm.
If that’s the case, then something must have gone wrong at the time the merge request was analyzed. In that case it will be interesting to look at the scanner output of the analysis of this merge request.

thanks for the respons @janos

I answer the question :

  1. What are the steps you take before this error appears?

We initiate setup sonar scanner from sonarcloud. execute sonar-scanner

sonar-scanner -D sonar.sourceEncoding=“UTF-8” -D sonar.sources=“src/” -D sonar.exclusions=“node_modules/,/.test.js?,**/.test.ts?”
-D sonar.inclusions="/*.js?,/*.ts?" -D sonar.projectKey=$SONAR_PROJECT_KEY -D sonar.projectName=$SONAR_PROJECT_NAME
-D sonar.projectVersion=$SONAR_PROJECT_VERSION -D sonar.organization=$SONAR_ORGANIZATION -D sonar.qualitygate.wait=true
-D sonar.javascript.lcov.reportPaths=“coverage/lcov.info”

  1. Where exactly does this error appear?

when we merge-request sonar-scanner, but when push ini develop branch sonar-scanner running well

    • If you go to your project in SonarCloud, navigate to the list of pull requests, do you see this pull request listed? (“pull request” is a term we use that’s equivalent to “merge request” on GitLab.) Also:
  • Do you see any other pull requests listed?

no, im not see other merge request, compared with default branch (develop)

  • If you visit the url in your browser, do you get a successful response, or is it 404?

still 404

hi @janos

any update for this?

Ok, so since the pull request is not created at SonarCloud side, it looks like something goes wrong with the analysis of the merge request.

In this case the first to look at is the output of the scanner command of a merge request. Can you copy-paste it? For now I’m most interested in the end part, it should look something like:

INFO: Analysis report generated in 125ms, dir size=445 KB
INFO: Analysis report compressed in 61ms, zip size=108 KB
INFO: Analysis report uploaded in 49ms
INFO: ANALYSIS SUCCESSFUL, you can find the results at: https://sonarcloud.io/dashboard?id=your-project-key
INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
INFO: More about the report processing at https://sonarcloud.io/api/ce/task?id=some-task-id
INFO: Analysis total time: 28.172 s
INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
INFO: Total time: 29.610s
INFO: Final Memory: 48M/170M
INFO: ------------------------------------------------------------------------

Another thing that could be interesting is Administration / Background Tasks page of the project. If the scanner output shows success, then there can a failure at our side processing the scanner report, and you would see those failures on this page.

hi @janos thanks for the response

this is the output of scanner command when merge requests.

INFO: Auto-configuring pull request 1860
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 46.309s
INFO: Final Memory: 6M/24M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarScanner execution
ERROR: Could not find the pullrequest with key '1860'
ERROR: Caused by: Error 404 on https://sonarcloud.io/api/alm_integration/show_pullrequest?project=xxx_xxx&pullrequestKey=1860 : {"errors":[{"msg":"Unable to find the pullrequest with key \u00271860\u0027"}]}
ERROR: 
ERROR: Re-run SonarScanner using the -X switch to enable full debug logging.
Authenticating with credentials from $DOCKER_AUTH_CONFIG
00:01
ERROR: Job failed: exit code 1

Looking at the code, the only way I see for this failure is if the merge request 1860 does not exist in the corresponding repository. Please verify the following:

  • Open your project in SonarCloud. Make sure that the value in ?id=... matches the value in ?project=... in the failure message of the scanner.
  • On your project’s page in SonarCloud, you should see a GitLab icon next to the project’s name, which should be a link to the corresponding project on GitLab. Go there.
  • On the GitLab project where you arrived from SonarCloud now, if you look at Merge requests, does the merge request with 1860 really exist?

ah i see. i think i found the problem.

thankyouu @janos