Avoid building 'master' from forks via cron

How can we stop nightly builds from being run on PRs coming from a master branch?

A config like below will run nightly-job not just for user/project/master but also for otheruser/project/master.

workflows:
  do-nightly:
    jobs:
      - nightly-job
    triggers:
      - schedule:
          cron: "0 0 * * *"
          filters:
            branches:
              only:
                - master

We have a workaround that runs a shell script checking $CIRCLE_PROJECT_USERNAME, but jobs still get queued and run.

@afeld posted a solution in Create separate steps/jobs for PR/Forks versus branches (thread closed, or I’d have bumped this there) that does not require actually running anything:

jobs:
  - forks_only:
      filters:
        branches:
          # only from forks
          only: /^pull\/.*$/
  - canonical_repo_only:
      filters:
        branches:
          # only from canonical repository
          # https://stackoverflow.com/a/5334825/358804
          only: /^(?!pull\/).*$/

Does this still work? The documentation does not specify what string is matched against, or if a non-regex match matches any part, just the branch name part, in total or in part.

Clarification would be greatly appreciated.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.