CircleCI Ideas

Realtime conditions for Orbs

Orbs are nice and all but it really is not useful if I can not call them with certain conditions.

 
In CircleCI 2.0 I can do shell commands to have conditional logic, but it seems with reusable Orbs, I can not use any of those conditions since it is all YAML.
Pls take a look at what Ansible did with its when condition and Jinja2 templating code.
 
I was trying to do some conditions on environment vars but it seems CircleCI 2.1 is just preprocessed code that converts to 2.0 code so something like
 
parameters:
      circle-pull-request:
        description: The URL of the associated pull request. If there are multiple associated pull requests, one URL is randomly chosen.
        type: string
        default: $CIRCLE_PULL_REQUEST
 
      circle-tag:
        description: The name of the git tag, if the current build is tagged.
        type: string
        default: $CIRCLE_TAG
 
    steps:
      - checkout
      - when:
          condition: << parameters.circle-pull-request >>
          steps:
            - run: |
                echo "when parameters.circle-pull-request: << parameters.circle-pull-request >>"
 
      - unless:
          condition: << parameters.circle-pull-request >>
          steps:
            - run: |
                echo "unless parameters.circle-pull-request: << parameters.circle-pull-request >>"
 
      - when:
          condition: << parameters.circle-tag >>
          steps:
            - run: |
                echo "when parameters.circle-tag: << parameters.circle-tag >>"
 
      - unless:
          condition: << parameters.circle-tag >>
          steps:
            - run: |
                echo "unless parameters.circle-tag: << parameters.circle-tag >>"
 
Will not work at all and I will always get the When conditions. This is quite sad because If I want to do something as simple as use the Slack Orb to send a notification based upon something at runtime, I have to literally copy paste the Slack Orb code into my config (which is what CircleCI processing does anyway).
  • Avatar32.5fb70cce7410889e661286fd7f1897de Guest
  • Dec 3 2018
  • Taking votes
  • Attach files
  • Admin
    Nathan Dintenfass commented
    07 Jan 23:07

    It is true that orbs are processed in advance of your runtime environment -- they are packaged configuration, rather than runtime binaries. That said, we definitely intend to expand the power of conditionals in CircleCI configuration. In the particular case you are showing here, the limitation is that we don't (yet) have any way to have an expression that tests for equality -- we only react in `when` to boolean values, where the empty string is falsey, and all other strings are truthy. That limitation is something we do hope to address.