It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Can I trigger Bitbucket pipeline with pull request?

Marian Jureczko Oct 13, 2016

Normally the pipeline is triggered by push. There is the possibility to configure an 'on pull request' webhook, but how to connect it with a pipeline and disable or reconfigure the default 'Pipelines' webhook which triggers on push?

9 answers

1 accepted

2 votes
Answer accepted
Brian Maissy Jan 10, 2019
Oleg Sigida Jan 10, 2019

Hi Brain, will it be triggered when a PR is merged/closed? 

Brian Maissy Jan 10, 2019

No; it will be triggered when a PR is created or updated (the source branch of the PR is pushed to).

When it is merged, the relevant pipelines on the target branch will run, if they are configured.

For example, I configured my pipelines to run tests on pull requests, and on the master branch. So when I merge a pull request to master, the tests run on master because of the configuration of master, not because of the configuration of the pull requests.

Like Eric Horodyski likes this
Oleg Sigida Jan 10, 2019

good to know, thanks! 

I deploy PR's to an environment for integration tests, and looking for a way to clean up resources when a PR has gone... 

Like Jordi Bassaganya likes this
Enric Soler Rastrollo Jan 21, 2019 • edited

Hi Brian, there's any way to have the source and destination branch?

In branch' triggered pull requests I have the BITBUCKET_BRANCH that allow me to execute some script in order to run some code, but not in PR triggered pipelines.


Edit: with this line you can have the origin branch

export BRANCH=$(git branch | grep \* | cut -d ' ' -f2)


Brian Maissy Jan 21, 2019

You can get the destination branch with the BITBUCKET_PR_DESTINATION_BRANCH variable

Eric Horodyski Jan 28, 2019

Thank you. This is _very_ important for me. I run a team of 3 developers and contractors that float in-and-out. We manage a dozen repos and quality-checking is a big issue for us. In addition to manual code-reviews, making sure all tests run as the PR is created or updated is one less step I need to take. 

Like Ashvin Narayanan likes this
Ashvin Narayanan Feb 24, 2019 • edited

@Brian Maissy In the documentation it reads "When it's triggered, we'll merge the destination branch into your working branch before it runs. If the merge fails we will stop the pipeline."

So is my understanding (below) correct:

  1. It won't get to the pipleline steps if the merge fails
  2. The Pull Request will be created regardless, but would have the usual warning sign next to the Merge button that informs about conflicts

If this is indeed the case, how do I execute steps on merge failure?

Is  after-script applicable here? 

Brian Maissy Feb 24, 2019

Yes, I think your understanding is correct.

I'm not sure if the after-script will run or not in that case; I would just check and see.

8 votes
Greg Inman Sep 01, 2017

Yeah, I would love this feature. The ideal workflow in my mind is to have the build pass as a requirement before merging the Pull Request. This keeps your deployment branches clean. After the PR is merged, the current feature set is nice to watch master/development branches and deploy them as changes are made (ie PRs are merged).

5 votes
Marco M Mar 04, 2018

Actually, never mind that - a search reveals no current issue open on the subject, so I created one:

please vote it if you'd like this feature.


3 votes
Robert Massaioli Atlassian Team Oct 13, 2016 • edited Nov 25, 2018

So the idea here is that instead of running your pipeline on every push you run it on every PR creation?

Is it not more convenient to build and test your code ASAP?

Update: I have funnelled the feedback about the expense of up to date deploys back to the Bitbucket Pipelines team.

Jan Steinke Jul 22, 2017

yes, you are right, it is more convenient to test code ASAP but for a small private or open source project you quickly run out of your 50 minutes if you build on every push.

Like # people like this
Steve Taylor Feb 16, 2018

Exactly @Jan Steinke. Developers on any team should be encouraged to push their branches to remote often, even before raising a PR, without worrying about consuming build minutes on unnecessary builds. They can add [skip ci] to commit messages, but will often forget to do so.

Marco M Mar 04, 2018

+1 for this feature, and exactly for the reasons stated above.

If someone has made a feature request, could you please post the link, so we can upvote it?

Kye Russell Aug 31, 2018

This. It's a bit short-sighted to assume that every team has enough money for 'unlimited' build minutes. 

Like Jeremy Stafford likes this
Jordan Hansen Nov 10, 2018

@Robert Massaioli The points mentioned above are nice but I'd like it for my deploy section. I want everything in master to be deployed automatically. If I merge a PR, this is new code that I need deployed.

Like Kye Russell likes this
Jeremy Stafford Nov 14, 2018

Build everything = $$. Plus there may be times where I only want to perform certain actions on a PR but not a typical feature branch push. For example, when Joe is checking in code to remote feature branch for the weekend, I don't necessarily want to burn build time running static code analysis on incomplete code, but on a PR, I absolutely do.

Like Kye Russell likes this
Kye Russell Nov 14, 2018

This sort of ignorance of financial factors is the same sort of thinking that causes Atlassian to think that it's appropriate to skyrocket their Jira seat price if I dare wish to enforce on Two Factor Authentication for my users.

I digress.

3 votes
Thomas Bradshaw Atlassian Team Oct 13, 2016

Hi Marian,

At the moment it is not possible to trigger a pipeline on a pull request being created. However, pipelines run on the source branch will be displayed along with the pull request. If this is something you would like in the product please create a feature request at telling us what you'd like in this feature. 

1 vote
Yann ROBIN Nov 17, 2017

I needed to trigger bitbucket pipeline for every created pull requests. As this is not available by default, I've managed to do it with a simple zapier zap, here is the tutorial :

0 votes
Chad Hansen Nov 02, 2016

It would be, but when we start having to pay for minutes to build, I think I will want this feature too. That way I could setup pipelines to only run tests on the master branch, and if anyone creates a pull request to the master branch, those also get run through pipelines. This might help save some minutes.

Wiliam Baldisser Jul 27, 2017

totally agree with you. Just for info, there is a cache feature now that should save some seconds on each pipeline run. 

0 votes
Misha Wakerman Oct 03, 2017

We also want to have this feature and came up with a workaround outlined here:

0 votes
Oleg Sigida Oct 03, 2018

as a workaround, you can push an empty commit

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Bitbucket Pipelines

Building a Bitbucket Pipe as a casual coder :  #!/bin/bash source "$(dirname "$0")/" enable_debug extra_args="" if [[ "${DEBUG}" == "true" ]]; then extra_args="--verbose" fi # mandatory variables R...

1,731 views 1 18
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you