Jenkins merge in stable branch to each PR before building

Viewed 1532

I have a Jenkins project where I want to merge in the latest origin/master into the feature branch before the build. A pull request is made through BitBucket to kick off the process.

I'm using the Git Plugin and under source code management, the repository URL is what I would use as a git clone for the project.

For branches to build, I'm using **/pull-requests/** to ensure the only branches built are the ones attempting to merge into master.

Under additional behaviors, I have Merge Before Build and the values are as follows:

Name of repository: origin
Branch to merge to: master
merge strategy: recursive
fast-forward mode: --ff

This didn't work. When I tried it, the build was still unstable based on pmd issues already merged into master from another feature branch.

EDIT

I've also tried using git commands according to this answer in both the Prepare an enviroment for the run and Under Build Enviroment -> Execute shell script on remote host using ssh. Both times it didn't work, but maybe I implemented it wrong?

1 Answers

The solution I found was that in the Additional Behaviors, I needed to Wipe out repository & force clone. After that change, the merge worked at is should.

For my understanding of what was going wrong:

Before wiping the repo, it was using a previous build commit for the merge. So when the merge happened, the merge commit was ahead of what was actually being merged and built. Then the pmd/checkstyle would fail because it was testing the pre merge commit.

I found this solution here: https://issues.jenkins-ci.org/browse/JENKINS-43485

Related