Workflows for master and develop

I’m trying to create separate jobs for branch development and merges to master. I’ve arrived at the following but now see that both workflows are executed, when I had expected only one could ever be triggered. What am I misunderstanding?

workflows:
    build_branch:
        when:
            condition:
                not:
                    -   equal: [ master, << pipeline.git.branch >> ]
        jobs:
            - side_chain_build
            - chrome_ex_build
            -   web_upload_assets:
                    requires:
                        - side_chain_build
                        - elm_runtime_build
    build_release:
        when:
            condition:
                equal: [ master, << pipeline.git.branch >> ]
        jobs:
            - side_chain_build
            - elm_runtime_build
            - chrome_ex_build
            -   web_upload_assets:
                    requires:
                        - side_chain_build
                        - elm_runtime_build
                        - chrome_ex_build
            -   web_release:
                    requires:
                        - side_chain_tests
                        - web_upload_assets

what is the difference between when and condition

1 Like

Hi @Simon!

Thanks for posting the example. Instead of they keyword condition, can you try using a specific condition such as and or or after when. The keyword when indicates to check for a condition, while specific keywords So for example, can you try the following:

version: 2.1

jobs:
  test:
    docker:
      - image: circleci/node:latest
    steps:
      - run: echo << pipeline.git.branch >>

workflows:
    do_not_build:
      when:
        and:
          - not:
              equal: [ master, << pipeline.git.branch >> ]
      jobs:
          - test
    build:
        when:
          and:
            - equal: [ master, << pipeline.git.branch >> ]
        jobs:
            - test

I think that you bring up a very good point about when vs condition. So condition predates this conditional logic syntax, as it allows you to use parameters. I think what’s happening here is that something is getting passed into condition, and even though it should be interpreted as “condition: false”, instead the condition is accepting any value as true.

I’m bringing this to the larger team to get some more eyes on it, as I was able to reproduce this unexpected behavior. Thanks again for your thorough use of CircleCI!

1 Like

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