Using an environment variable to skip a job

I want to make one of the jobs in my pipeline optional based on an environment variable. The reason is the job takes a long time (e.g. an hour) but it doesn’t need to be done every time - for example, not when re-deploying the same piece of work.

I created an environment variable for the project called DISABLE_ENV_SETUP and set it to 1.

Then I put this in the config.yml:

jobs:
    build_env_setup:
        <<: *defaults
        steps:
            - run:
                name: Skip env set up if disabled
                command: if [ -z "${DISABLE_ENV_SETUP}" ]; then echo "Skipping env set up because of CircleCI environment variable DISABLE_ENV_SETUP."; circleci step halt; fi

Unfortunately this doesn’t work.

I’m not sure if I’m using the environment variable incorrectly or am misunderstanding something. Can anyone help?

Making all the environment variables in the project redacted is kind of annoying. It should be a toggle (if it is for a secret or a password).

I think I can’t even echo it can I, it’ll still get redacted? It’s difficult for me to debug why that step is not doing anything.

Just noticed my test is doing the opposite of what I want - it’s testing for emptiness.

I’ve changed it to if [ ! -z "${DISABLE_ENV_SETUP}" ];