SonarCloud not working as expected on pull request closed to main branch


We are running the SonarScanner on GitHub actions and pushing the results to SonarCloud using the maven-sonar-plugin:

Our pipeline is triggered using:

    types: closed
    branches: main

We use the previous version option for the new code definition.

As the event is a GitHub pull_request and not a push to main, the pom.xml version is not pushed to SonarCloud. SonarCloud has always the same version as a reference for new code due to no new versions being pushed.

It works as expected using:

      - main

Shouldn’t the pull request close event work like the push event?

Any solution to make SonarCloud work with the pull request close event?


Hey there.

I wouldn’t expect the pull request “close” event to work like a push event – in that case (and as you’re experiencing) the analysis is going to run in the context of the pull request and not of the branch the pull request was merged into (if it was merged).

Why do you want to use this kind of trigger as opposed to using the push on the main branch?