I am using Github Actions, and triggering SonarCloud Scan for PRs. Which works really well, if the trigger used to start the action is pull_request.
For some reasons, I have to use pull_request_target instead, which is bringing some problems.
SonarCloud Actions just doesn’t understand that it refers to a Pull Request, and applies the scan for the target branch.
This is a short of my Github Action now.
I could make it work and reference the PR using sonar.pullrequest.key=${{github.event.pull_request.number}}
But this brought me another problem: SonarCloud doesn’t report back status to github.
I am restricting my PRs to only be merged when SonarCloud gate is fine, so I need SonarCloud reporting back. But for some reason, the combination of pull_request_target with SonarCloud action, even referencing the PR, is not working.
I suppose your difficulty here is down to the fact that those two triggers have different properties. Note the difference in the SHA and ref between pull_request_target and pull_request.
Since you’re not going the anticipated route, you’ll need to build all of it from scratch. The docs can help with analysis. For Quality Gate status, take a look at the sonar.qualitygate.wait property, as discussed here.
Would you mind explaining why you need to use pull_request_target rather than pull_request?
We have some steps during our CI/CD process which commits with [skip ci] message.
In our case, makes sense to keep that way, so we can skip some workflows.
So the PR (test-sonar → dev) is running the validation, and Sonar is commenting on this PR as expected. But it keeps blocked waiting for status, which actually is reported to dev -> main PR (even though this PR doesn’t run Sonar validation).
You’re saying the Quality Gate status is reported in the wrong place & the right place is stuck waiting for a status update that never comes?
Again, this is likely because the wrong envvars are being picked up because an unexpected trigger is used. We haven’t made any effort to document what it is you’ll need to override because… there was no anticipation of your alternate route, and it’s just supposed to work.