5

In the project I am currently working on, I want to run the bitbucket pipeline according to the following rules.

  • Test and lint steps should run for each commit pushed to Branch.
  • The test-with-coverage and lint steps must be run for each record opened with Pull Request.

The problem here is that if I push a commit to a branch that I have opened a pull request, the pipeline is triggered twice.

pipelines:
  default:
    - step: *lint
    - step: *test
  pull-requests:
    '**':
      - step: *lint
      - step: *test-with-coverage

I looked for a way to skip default pipeline if a pull request exists, but I can't find it. I am open to suggestions and opinions.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
T. Ç
  • 75
  • 1
  • 7
  • 1
    Curious, but why wouldn't you want tests run when a pull request is updated? The PR is only updated if something changes, so you'd be skipping tests on those new commits - and letting potentially bad code through as a result. – Jim Redmond Dec 03 '19 at 18:30
  • I don't want to skip tests on pull request. However, if there is a PR, I want to run different pipeline. In branch, I only run tests. However, if there is PR, I want to run test with minimum code coverage limit (Only if there is a pr). I'll add sonarqube if there is a pipeline as well. – T. Ç Dec 05 '19 at 20:52
  • Did you figure it out maybe? I have exactly the same question :) – rantoniuk Jan 15 '20 at 18:16
  • Unfortunately I couldn't find any way to do this :( – T. Ç Jan 27 '20 at 19:59

1 Answers1

-1
pipelines:
  default:
    - step: *lint
    - step: *test
  rules:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
      when: never
  pull-requests:
    '**':
      - step: *lint
      - step: *test-with-coverage



  • Where did you find the "rules:" block? I cant find anything about this and it does not work for me in my build. I do see some info about a "conditions" block https://support.atlassian.com/bitbucket-cloud/docs/configure-bitbucket-pipelinesyml/ but while that is at least recognized as valid it still does not achieve the desired effect of above – Rhineb Sep 01 '22 at 16:11