How to deploy only on tagged and master commits

I’ve been trying to implement a workflow which contains three jobs. The first one, named “build”, builds the application, the two others are deployment jobs. Here are the requirements for those two jobs:

Job "deploy_to_development"

  • Require “build” job to be completed
  • Only run on the master branch

Job "deploy_to_production"

  • Require “build” job to be completed
  • Only run on the master branch
  • Only run on a tagged commit with format /^v.*/

The relation between those requirements is a logical AND. One would expect the following configuration to fulfill those needs:

workflows:
  version: 2
  build_and_deploy:
    jobs:
      - build:
      - deploy_to_development:
          requires:
            - build
          filters:
            branches:
              only:
                - master
      - deploy_to_production:
          requires:
            - build
          filters:
            tags:
              only: /^v.*/
            branches:
              only:
                - master

But unfortunately, multiple filters behave like a logical OR. Is there any workaround to achieve my goal? I’ve tried unsuccessfully to hack the configuration with ignores or even negative lookahead regexes.

Hi @IGassmann, you are correct, the filters behave as an OR not AND. The current configuration with deploy_to_production is going to be the closest to meeting this use case and will limit builds to only the tag filter or the master branch.

Please note that the tag filter will also need to be included in the build job as well, as tags are inherited:

      - build:
          filters:
            tags:
              only: /.*/

Others are interested in having this behave as an AND as well. If you have a moment, please add your vote to this Idea post.

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