Manually triggered Github workflows on branches are pushed to main on sonarcloud.io

Template for a good new topic, formatted with Markdown:

  • ALM used: GitHub
  • CI system used: GitHub
  • Scanner command used: `./gradlew sonar --info
  • Languages of the repository: Kotlin
  • Error observed: When manually starting a workflow on a branch or tag, the results are publish on Sonarcloud.io as if run on the main branch. I expect this to be published as a branch run, shown in the Branches overview.
  • Steps to reproduce: Manually trigger a Github workflow on a gradle project on a branch.
  • Potential workaround: None known so far.

This seems to be the exact issue as described here: SonarCloud Github: always pushed to main branch on "workflow_dispatch"

Hey there!

We’ve seen this before. @sodul was kind enough to provide a workaround:

and I confirm there’s a ticket in our backlog to autoconfigure the branch when executed via workflow_dispatch

Hi Colin, has this even been done? I’m having the same issue: running by workflow_dispatch on some branch but Sonar thinks it’s main.

Hey @heruan

Sorry to report the ticket is still open on our side. I can just point to the workaround shared by @sodul.

Thank you for the quick feedback! I have tried the workaround, but I couldn’t make it work. I’m using the Gradle plugin and it does not read sonar-project.properties and does not seem to pick up the environment variable when configured in the task properties.

Do you think this is something that could be fixed in the short term? This behavior is messing up the history of the main branch analysis.