Pipeline requirements:
- We have branches for our development-staging (dev), staging, and production (release) environments.
- For every pull request, we want to run build and test steps before it gets merged into the target branch, to ensure that we don't merge broken code.
- Once a PR is merged into an environment branch, the branch is built, tested, and deployed.
The problem:
When I open a PR to merge master into staging (or staging into release), two pipelines are triggered: one for the PR and one for master branch. This triggers the deploy step for the master branch unnecessarily.
The documentation mentions this, but doesn't give any direction on how to prevent the two pipelines from running.
Is there a way to check if it's a pull request inside the master pipeline definition and cancel the pipeline if it is?
Here's the relevant part of my `bitbucket-pipelines.yml` file:
pipelines:
pull-requests:
'**':
- step: *build-test
branches:
master:
- step: *build-test
- step:
<<: *docker
deployment: Dev
staging:
- step: *build-test
- step:
<<: *docker
deployment: Staging
release:
- step: *build-test
tags:
v*:
- step: *build-test
- step:
<<: *docker
deployment: Production
trigger: manual
Hi @david-cofi and welcome to the community!
If you open a PR without pushing any new commits to master, only the pull-requests pipeline should run, and not the master one.
Could you please let me know how you open the PR? From Bitbucket UI? Or are you doing something different?
Or are you perhaps pushing commits to master, when an existing PR with master as source branch is open? Because in this case, if you push commits to master when a PR is already open, two builds will indeed run.
In this case, you can avoid the duplicate builds by including the text [skip ci] anywhere in the commit message of the latest commit you are pushing to master. If you do that, when you push to master, only the pull-requests build will run (for the open PR) and no build will run for master.
If this is not your use case, please provide some further info on the exact steps you take so we can further investigate.
Kind regards,
Theodora
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.