Multibranch pipeline pull request fetch target branch

I have integrated my Jenkins multibranch pipelines with SonarQube.
The integration triggers the Sonarqube analysis in a different way depending if a normal branch or a pull request is evaluated.
In case of pull request the integration triggers a pull request analysis passing all the required parameters: pull request branch, base branch etc.
Unfortunately the analysis performed is not complete and by having a look to the Sonarqube documentation it looks like the analysis tool needs the target branch to be fetched locally as well.
My understanding is that the Multibranch pipeline just fetches the current branch being built only and ends up on a detached state with the HEAD pointing to the commit being built.
I have tried to fetch the target branch in multiple ways:

  • Using the git credentials binding plugin (Git username / password credentials binding),
  • Using skipDefaultCheckout() and customizing the checkout phase,
  • Manually use git fetch trying to pass username and password in the git url

I always end up having authentication issues. I have been wrapping my head around this for a day and before exploring anything else I would like to know if there is something I am missing… maybe the Multibranch pipelines are already providing this functionality or there is a better way to obtain this instead of what I have tbeign trying.

Any ideas?.

1 Like

Try adding the following traits to have the Multibranch Pipeline checkout to trigger a more complete clone including both source (non-detached) and target branches for your PR:

  • localBranchTrait()
  • refSpecsSCMSourceTrait { templates { refSpecTemplate { value('+refs/heads/*:refs/remotes/@{remote}/*') } } }
1 Like