jenkinsci / bitbucket-push-and-pull-request-plugin

Plugin for Jenkins v2.138.2 or later, that triggers job builds on Bitbucket's push and pull request events.
https://plugins.jenkins.io/bitbucket-push-and-pull-request
MIT License
46 stars 50 forks source link

Pipeline executed from wrong branch when using Lightweight checkout #312

Open karniemi opened 8 months ago

karniemi commented 8 months ago

We have configured a Jenkins job:

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 commented 8 months ago

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 commented 8 months ago

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.)