bitbucket-push-and-pull-request-plugin icon indicating copy to clipboard operation
bitbucket-push-and-pull-request-plugin copied to clipboard

Pipeline executed from wrong branch when using Lightweight checkout

Open karniemi opened this issue 2 years ago • 4 comments

We have configured a Jenkins job:

  • a pipeline which is checked out from git
  • using a build parameter "BRANCH_NAME"
  • and "Branch Specifier" as "refs/heads/${BRANCH_NAME}"

This allows us to trigger the job manually for whatever branch - and also trigger the build using the Bitbucket Push and Pull Request Plugin.

We wanted to start using Lightweight checkout - to prevent doing the checkout twice from git. Unfortunately, when we enable "Lightweight checkout", the Jenkinsfile is no more executed from the branch which the PR was made and which started the build - but some other branch. If we again disable "Lightweight checkout", the Jenkinsfile is executed from the branch as supposed to.

karniemi avatar Nov 01 '23 10:11 karniemi

Of course, this could be turned the other way round: when Lightweight checkout is disabled and the Bitbucket Push and Pull Request Plugin triggers the build - the Jenkinsfile is not taken from the branch which is configured in the Jenkins job, but instead the Jenkinsfile from the PR-branch is picked.

This is actually what we( in my org) want though, but it's most illogical for users in UI perspective.

karniemi avatar Nov 01 '23 12:11 karniemi

For "Lightweight checkout: enabled", I tried setting to "Branch specifier: refs/heads/${BITBUCKET_SOURCE_BRANCH}", hoping the plugin would set the BITBUCKET_SOURCE_BRANCH in the ENV , and therefore the Jenkinsfile would be checked out from the correct branch. But no, it was still using some wrong branch. ( For this experiment, I also had a build parameter named BITBUCKET_SOURCE_BRANCH - but that should not cause the issue, because according to Jenkins docs/statements environment variables cannot be overridden by the build parameters.)

karniemi avatar Nov 01 '23 14:11 karniemi

@karniemi Hi! Thanks for reporting. Unfortunately I cannot replicate the issue. Maybe you can try sharing more specifics such as if this problem happens with bitbucket cloud or server. Did you try using just the branch name without the refs/heads/ part?

julioc-p avatar Sep 20 '24 14:09 julioc-p

This was happening with Bitbucket server. I did not test with plain branch name, because plain branch names are ambiguous and therefore using them is not recommended.

I'm no longer working for the project in which this was discovered, so I'm not able to perform any further troubleshootings steps. And the guys still working for it, probably do not care.

karniemi avatar Sep 24 '24 13:09 karniemi