3

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?

DarkHark
  • 614
  • 1
  • 6
  • 20
  • `origin` is the name of your remote server used to sync your repo. Try to add the Git repository name. – Moerwald Jun 05 '19 at 12:55
  • stderr: fatal: ambiguous argument 'practiceRepo/master^{commit}': unknown revision or path not in the working tree. When I used origin, the build didn't completely fail. – DarkHark Jun 05 '19 at 13:16
  • Using origin, in the jenkins log, I eventually get this line, "Commit message: "Merge branch 'master' of bitbucket.url-to-my-project-repo.com into feature-branch-name". Although it says this, it does not seem like that's actually happening because the build was still unstable based on pmd issues already corrected and merged into master from another feature branch. – DarkHark Jun 05 '19 at 13:41

1 Answers1

0

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

DarkHark
  • 614
  • 1
  • 6
  • 20