Is it possible to create a condition using the result of a bash script?

Hi everyone,

I want to continue the execution of job only if the result of a bash script is true.

I tried the solution here using env variables, however as the caveat there says, it doesn’t work on when which is exactly what we need as we perform complex conditions inside the bash script.

Is it possible to do that?

This is an example of our configuration file:

check_for_condition: &check_for_condition
  name: Check for my special condition
  command: |
    sudo chmod +x /home/circleci/project/script.sh
    bash /home/circleci/project/script.sh
    # This step will populate the environemnt variable MY_FLAG, to be used in the next step

build-job:
  executor: python
  parameters:
    my_flag:
      type: env_var_name  # note the special type
      default: MY_FLAG
  steps:
    - checkout
    ### Check for my condition
    - run: *check_for_condition
    - run: echo "Conditions were met? 'my_flag'=$<<parameters.my_flag>>"
    - when:
        condition:
          or:
            - equal: [main, <<parameters.branch>>]
            - equal: ["true", $<<parameters.my_flag>>]
        steps:
          ### Run if condition above is met
          - next_steps_here:
          - next_steps_here:
          - next_steps_here:
          - next_steps_here:

Not in the way that you have expressed in your example.

The limitation is that conditions are evaluated at the time the config.yml file is compiled and so dynamic checking is not possible.

The solution to this issue is the “Dynamic Config” feature, which would allow you to collect the dynamic info you need and then pass it on to an independent yml script that can accept the info as parameters.

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