Could not find pullrequest with key ''

Very similar to Could not find the pullrequest with key
This used to work fine for us and then stopped a few months ago. We are using the stand alone Sonar Scanner for analysis. The “Run Code Analysis”(v 1.40.0) optional Task fails anytime a new PR is created. The pipeline itself “Generic analysis with SonarCloud-CI” can be ran successfully but not when invoked for a PR.

Do I indeed need to delete the entire project from SonarCloud and recreate it?

YAML FILE:

pool:
  name: Azure Pipelines
  demands: java

  timeoutInMinutes: 1000000000

steps:
- task: SonarSource.sonarcloud.14d9cde6-c1da-4d55-aa01-2965cd301255.SonarCloudPrepare@1
  displayName: 'Prepare analysis on SonarCloud'
  inputs:
    SonarCloud: SonarCloud
    organization: ***************
    scannerMode: CLI
    configMode: manual
    cliProjectKey: '******'
    cliProjectName: **********
    extraProperties: |
     # Additional properties that will be passed to the scanner, 
     # Put one key=value per line, example:
     # sonar.exclusions=**/*.bin
     
     sonar.exclusions=**/*.java,/Cloud/DBs/K8S/**/*,Website/jwplayer-7.11.3,Website/fabric.js-1.5.0*/**/*,Website/High*/**/*
               
     sonar.inclusions=Website//**/*,Cloud/**/*
  timeoutInMinutes: 15

- task: SonarSource.sonarcloud.ce096e50-6155-4de8-8800-4221aaeed4a1.SonarCloudAnalyze@1
  displayName: 'Run Code Analysis'
  timeoutInMinutes: 30

- task: SonarSource.sonarcloud.38b27399-a642-40af-bb7d-9971f69712e8.SonarCloudPublish@1
  displayName: 'Publish Quality Gate Result'
  timeoutInMinutes: 15

Hi,

Welcome to the community!

Can you verify that the PR exists in your DevOps platform before analysis runs?

Also can you provide the analysis log of the failing PR analysis?

The analysis / scanner log is what’s output from the analysis command. Hopefully, the log you provide - redacted as necessary - will include that command as well.

This guide will help you find them.

 
Ann


INFO: Found an active CI vendor: 'Azure DevOps'
INFO: Load project settings for component key: '[REDACTED]'
INFO: Load project settings for component key: '[REDACTED]' (done) | time=501ms
INFO: Process project properties
INFO: Execute project builders
INFO: Execute project builders (done) | time=0ms
INFO: Project key: [REDACTED]
INFO: Base dir: D:\a\1\s
INFO: Working dir: D:\a\1\s\.scannerwork
INFO: Load project branches
INFO: Load project branches (done) | time=500ms
INFO: Check ALM binding of project '[REDACTED]'
INFO: Detected project binding: BOUND
INFO: Check ALM binding of project '[REDACTED]' (done) | time=469ms
INFO: Load project pull requests
INFO: Load project pull requests (done) | time=469ms
INFO: Load branch configuration
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 45.091s
INFO: Final Memory: 20M/70M
INFO: ------------------------------------------------------------------------
##[error]ERROR: Error during SonarScanner execution
##[error]ERROR: Could not find the pullrequest with key '4943'
ERROR: Caused by: Error 404 on https://sonarcloud.io/api/alm_integration/show_pullrequest?project=ProjectEverCommerce_OfficeMD&pullrequestKey=4943 : {"errors":[{"msg":"Unable to find the pullrequest with key \u00274943\u0027"}]}
ERROR: 
ERROR: Re-run SonarScanner using the -X switch to enable full debug logging.

ERROR: Could not find the pullrequest with key '4943'
ERROR: Caused by: Error 404 on https://sonarcloud.io/api/alm_integration/show_pullrequest?project=[REDACTED]&pullrequestKey=4943 : {"errors":[{"msg":"Unable to find the pullrequest with key \u00274943\u0027"}]}
ERROR: 
ERROR: Re-run SonarScanner using the -X switch to enable full debug logging.
##[error]The process 'D:\a\_tasks\SonarCloudAnalyze_ce096e50-6155-4de8-8800-4221aaeed4a1\1.40.0\sonar-scanner\bin\sonar-scanner.bat' failed with exit code 1
Finishing: Run Code Analysis

Included the Analysis output, but the issue doesn’t seem to be the analysis itself. I can manually execute the pipeline against a specific branch like “develop” but I can’t execute it against a user specific branch for a PR.

Hi,

Are you absolutely sure the same PAT is used in both cases? Because that looks like a permissions issue.

 
Ann

Hi,

I have the same issue. Our PAT did expire, but I created a new one and updated SonarCloud. However, I still get the same error. It seems like it won’t fetch PR information if the PAT expired once, irrespective of whether you create a new one or not.

Some solutions I’ve seen suggest recreating the SonarCloud projects, but that’s a problem. I have a LOT of projects that will need to be recreated. Also, I don’t want to lose the history that’s been accumulated so far.

Kind regards,
Charl Marais

The following answer helped me:

The organization-level PAT also expired. Updating that fixed the issue.

Kind regards,
Charl Marais

2 Likes

Hello Joshua,

As Charl mentionned, your issue is probably related to an expired PAT (personal access token) or with incorrect rights.

We advise to always setup your PAT at organization level (Administration > Organization settings > Azure devops connectivity management) and remove all PAT at project level (that way when it expires, you only update it once at org level).

The procedure is explained there : Azure DevOps | SonarCloud Docs

You want to pay special attention at what’s explained in the yellow rectangle in the doc page.
Let me know if it helps.

Best regards,

Quentin

I’m looking into this now. I had previously updated the PAT on the SonarCloud side. I am looking on the Azure side according to your suggestion and will update this shortly.

It appears you are correct.
I had updated a PAT token previously, but I think I had done it at the project level and it had originally been setup at the organization level.

We’ve been messing with this for a few days and I have noticed more than a few threads along a similar vain. Now that I see it and have gone through it, it seems as straight forward as we thought it would be. That said, I think it’s worth asking why the nature of the issue itself isn’t more apparent or where the common disconnect is that is keeping users for recognizing both the issue and its remediation steps.

Constructive feedback from a customer that enjoys your product and the value it delivers to our team!
Keep up the fantastic work!

1 Like

Hi Joshua,

Happy it solved your problem, and thank you for the feedback.
We also noticed that you are not the only person being mislead by this error message, for sure we will have a look into it :slight_smile:

Have a good day !