Advanced Logic in Config

I’m happy to announce the recent addition of advanced
config-compile-time logic statements to config version 2.1. This is
part of our initiative to give users greater control over the work to
perform.

With logic statements you can combine literal values, pipeline values,
and pipeline parameters in various ways to produce arguments for when
stanzas in workflows and when steps.

A brief example:

my-job:
  steps:
    when:
      condition:
        or:
          - << pipeline.parameters.run-deploy >>
          - equal: [ master, << pipeline.git.branch >> ]
      steps:
        - run: ./deploy

This step will run on master, or if you specify the run-deploy
pipeline parameter via the API to trigger a manual deployment.

Head to the documentation or the configuration cookbook for more
details and examples.

6 Likes

This is a game changer

Just wonder if its possible to get something like this working

my-job:
  steps:
    when:
      condition:
        or:
          - condition_1
      steps:
        - run: ./deploy
    when:
      condition:
        or:
          - another condition
      steps:
        - run: ./deploy_2

Something of that logic,

Just to give some context, my comment comes from using this Orb CircleCI Developer Hub - circleci/path-filtering

So if no changes were detected, would be good to still return a success message - especially if you have github checks dependant on it

1 Like

I’d like to be able to only run codecov/upload if a coverage output directory is present, is there any way to do this?

It seems like it’s not possible to use an arbitrary shell command to determine a condition. Product managers may have thought we can already do conditional stuff in bash scripting but…when we need to run a command provided by another orb, we can’t do that because we can’t invoke the command from bash.

So, assuming I didn’t overlook such a feature in the docs, I hope you will add an option to use a shell command exit code as a condition

@sulami it would be nice to have a conditional expression language like GitHub Actions do like << pipeline.parameters.run-deploy >> || << pipeline.git.branch >> == 'master'