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.

Home Page:https://plugins.jenkins.io/bitbucket-push-and-pull-request

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Pipeline executed from wrong branch when using Lightweight checkout

karniemi opened this issue · 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.

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.

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