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

Hi,

We are running the SonarScanner on GitHub actions and pushing the results to SonarCloud using the maven-sonar-plugin: https://mvnrepository.com/artifact/org.sonarsource.scanner.maven/sonar-maven-plugin/3.9.1.2184.

Our pipeline is triggered using:

on:
  pull_request:
    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:

on:
  push:
    branches:
      - 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?

Thanks!

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?