Conditional workflows without spinning up an environment

We’ve started using conditional jobs and it is a really helpful feature.

As far as I see from my tests, the conditional job is calculated after the “Spin up environment” and “Preparing environment variable” stages finish.
I am wondering if there is a way to skip a job execution completely (without spinning the environment), similarly to how it is done by the branch filtering feature.

While this is a non-issue in docker-based jobs in which the “spin up environment” step usually takes 0-1 seconds (due to cache I presume), we have a docker-compose based job that uses a ‘xlarge’ sized VM.
Spinning it can take several minutes, which can only then lead to the condition check and the job being aborted.

I’m wondering if there is a way to avoid waiting those several minutes just to find out the the job should not even run.

Hi @ilia-cy,

Out of the box, execution will happen for a workflow even if there are no “running” jobs within that workflow because all steps have been excluded on condition since conditional steps are determined at execution and not compilation. As you have already experienced, this is not the same for conditional workflows, which will skip the jobs entirely.

Without seeing your config, it’s hard to tell exactly what you’re hoping to accomplish, but you may be able to get around this difficulty by having multiple workflows that run based on specific conditions. Additionally, you could look at implementing a dynamic config, which will build the secondary config based on the conditions in the setup config.

I hope this helps, please feel free to ask any followup questions you may have, or create a support ticket if you would like further help. Cheers!

Thanks for the response @zhudson!

I’ll try to be more specific.

Let’s say I have a config.yml that receives parameters.
The parameters are whether or not specific jobs should run:

    type: boolean
    default: false
    type: boolean
    default: false

The jobs are configured as following:

        type: boolean
        default: false
        type: string
      - image: cimg/base:2021.10
      - when:
          condition: << parameters.Should_Run >>
            - checkout
            - setup_remote_docker:
                version: 20.10.6
            - run:
                command: |
      - unless:
          condition: << parameters.Should_Run >>
            - run: echo "Nothing to do"

The workflow that runs these jobs looks like this:

      - My_Job_Name:
          name: Job1
          Should_Run: << pipeline.parameters.should-run-job-1 >>
          Path_To_Build: Path1
      - My_Job_Name:
          name: Job2
          Should_Run: << pipeline.parameters.should-run-job-2 >>
          Path_To_Build: Path2

What I’m saying is passing false in the should-build-job parameter will still trigger the “Spin up environment” and “Prepare environment variables” steps, as can be seen in the following image:

While this is fast in docker based images, doing the same with a job that is based on a machine:

      image: ubuntu-2004:202104-01
      resource_class: xlarge

Can take several minutes to run these 2 steps only to then calculate the parameter and understand that it should not run. See following image:

My question is whether there is a way to avoid running these jobs completely, without waiting for the image to load.

Thanks again!