Only build on specific branches and PRs

Hi there,

I’m using config version 2.1 and trying to achieve the following on steps:

  1. Only build commits pushed to master
  2. Only build commits pushed to develop
  3. Only build pull requests

I can easily achieve the firs two using:

workflows:
  version: 2
  test-and-deploy:
    jobs:
      - test:
          filters:
            branches:
              only:
                - master
                - develop

However how can I add to the filters, to also build pull requests?

Any help is appreciated!

4 Likes

PRs should be built by default - are they not being built with this config?

Are these PRs for the same user, in the same org, or in a fork?

Nope, not being built. Only commits pushed to master and develop. I’m following Git Flow, so all PR’s are based off of master or develop.

I read on one of the other posts, to try adding /^(?!pull\/).*$/, however this caused commits in every single branch to be built.

1 Like

Do you mean as a branch name filter? I am unfamiliar with how PRs are presented to Git inside the PR process - do they always get this as a prefix? If this is a branch name, then I wonder whether you would need an ignore rule as well - this is rather non-intuitive, but the docs do try to cover it.

See my demo here, particularly the only-deploy-tags section (and where that is injected into the workflows section).

1 Like