Problem with when-condition and empty string

Hello!

I have an orb, where I do something like this:

version: 2.1
description: My orb
commands:
  install-something:
    description: Install
    parameters:
      tool-revision:
        type: string
        description: Revision of tool to use
        default: \"\"
    steps:
      - run: "wget https://example.com"
      - when:
          condition: <<parameters.tool-revision>>
          steps:
            - run: echo HERE
      - unless:
          condition: <<parameters.tool-revision>>
          steps:
            - run: echo THERE

Whenever I call the orb command without setting the parameter I always end up in ECHO HERE.

The documentation states that it should behave differently:

Second link states:

You may use parameters as your conditions. The empty string will resolve as falsey in when conditions.

Edit: Also ~ or "" as default values does not make any difference.

Hi @nextl00p, I know you said you tried this with the default value of "" and it didn’t make any difference, but when I tried the following config things seemed to work as expected (the compiled config has the echo THERE):

version: "2.1"
orbs:
  myorb:
    commands:
      install-something:
        description: Install
        parameters:
          tool-revision:
            type: string
            description: Revision of tool to use
            default: ""
        steps:
          - run: "wget https://example.com"
          - when:
              condition: <<parameters.tool-revision>>
              steps:
                - run: echo HERE
          - unless:
              condition: <<parameters.tool-revision>>
              steps:
                - run: echo THERE
jobs:
  build:
    machine: true
    steps:
      - myorb/install-something

If you write that to a file and run circleci-cli config process [file] does it work for you?

Thanks for you response @johnswanson.

It’s running now with the unescaped double quotes. I tested it with those previously, but got another error, so I thought it still is the same issue.

The documentation is still wrong, isn’t it?

Yep, you’re absolutely right, thank you for pointing that out. I’ve just submitted a PR for the docs, the example with the \"\" default should be fixed as soon as that goes out. Thanks so much for letting us know, let me know if you have any other issues with orbs or config compilation!

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