ethrbunny
ethrbunny

Reputation: 10469

bamboo - build my pull request

Im trying to trigger builds in bamboo when a pull request comes into git. I can send the webhook info to bamboo but instead of building the appropriate sha-labeled checkin it just builds the 'master' branch.

Does this require some custom git setup to bamboo? Im not seeing anything straightforward so far.

In my last gig we used Jenkins and it seemed to tie together pretty well. I'm passing the sha-1 to bamboo with the pull request. Now I just need to convince it to use it.

Upvotes: 2

Views: 1389

Answers (2)

rluisn
rluisn

Reputation: 1

If you are using bamboo spec yaml.

You can use the option for-pull-request: it will run every time a pull request is created or updated.


version: 2
plan:
  project-key: PROJ
  key: TASK1
  name: TASK
  description: You description
  master-branch: develop
...
branches:
  create:
    for-pull-request:
      accept-fork: true

This is an example of a Bamboo plan configuration written in YAML format.

The version field indicates the version of the YAML syntax being used for this file.

The plan section describes the basic information about the Bamboo plan. It includes:

  • project-key and key fields, which are used to identify the plan within the Bamboo project.
  • name and description, which are used to display the name and description of the plan within Bamboo.
  • master-branch, which specifies the default branch used for the plan.

The branches section contains settings for branch behaviors:

  • create creates new branches.
  • for-pull-request is a specific branch matching pattern that accepts pull request builds.
  • accept-fork allows for forks of repositories to be built automatically.

These settings will configure how your Bamboo pipeline treats branches when they are created or updated.

Upvotes: 0

ethrbunny
ethrbunny

Reputation: 10469

Turns out the trick is to capture the id of the pull request from git and use this to checkout the appropriate version from git.

Inspiration from here. I ended up using php to parse the output from the git hook.

Use this to get the right bits from git (on your bamboo box):

cd ${bamboo.build.working.directory}
git fetch https://github.com/person/some_util +refs/pull/${bamboo.pull_num}/merge:
git checkout FETCH_HEAD

Upvotes: 2

Related Questions