Run a job if condition is met


Can someone please assist with the following configuration?

Under this job, want dynamically to run the step “My step” - based on the value of the enthronement variable RUN_SECOND_STEP


      - image: cimg/node:lts
    resource_class: small
      - run:
          name: Set parameter
          command: echo 'export RUN_SECOND_STEP=true' >> $BASH_ENV
      - when:
          condition: << $\{RUN_SECOND_STEP\} == "true" >>
            - run:
                name: My step
                command: echo "My step"

There are 2 issues

  • Firstly the circle.yml is processed when the CI job is first run, so before environment variables are known and so the conditional checks are unable to check environment variables.

  • Secondary the circle.yml file is processed within a shell environment that executes other shell environments. This means that it has loaded $BASH_ENV when it was started. Any changes made to $BASH_ENV as steps are run will not be seen by the circle.yml shell.

To do condition checks on environment variables you will need to move them inside the ‘run’ command. This means that the step will always run, but may just exit quickly if the conditions are not met.