Build with conditionals not working

I’m trying to build based on the branch is being deployed, to test the idea created a small job that should execute one command if in the correct branch:

version: 2.1
jobs:
  build:
    docker:
      - image: circleci/openjdk:8-jdk
    working_directory: ~/repo
    steps:
      - checkout
      - when:
          condition:
            - equal: [ "circleci_automation", << pipeline.git.branch >> ] 
          steps:
            - run: ./test.sh

but when I run this I’m getting the error:

   Job may be a string reference to another job
2. [#/jobs/build] expected type: String, found: Mapping
|   |   |   |   |       - << pipeline.git.branch >>
|   |   |   |   |       - main
|   |   |   |   |     - equal:

This is how documentation states this should be done, any idea why it’s failing?

Hello @walterjota, and welcome to the CircleCI Discuss community!

Although I replied to the Support ticket you submitted about this issue, I’d like to share the solution here too (a solution that you had already figured out in the meantime), in case another user encounters the same problem.

The error was caused by the extra - (hyphen-minus character) placed before the equal key. The correct syntax is:

  - when:
      condition:
        equal: [ "circleci_automation", << pipeline.git.branch >> ] 

You can find examples of logic statement in our documentation.

1 Like

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