How to set a variable in workflows?

My build tasks are similar, but with only one variable changed.

So I want to use environment in workflow, but I don’t see any sample about it.

Below is the code I want to use variables in workflow, but not sure if it works or not

version: 2
jobs:
  terraform_plan:
    docker:
      - image: hashicorp/terraform:0.11.7
    environment:
      TF_VAR_TAG: project1
    steps:
      - checkout
      - run: terraform init -backend-config=config/${ENV}.config
      - run: terraform get --update
      - run: terraform plan -var-file=conifg/${ENV}.tfvars

workflows:
  version: 2
  dev_plan:
    jobs:
      - terraform_plan
    environment:
      ENV: dev
  svt_plan:
    jobs:
      - terraform_plan
    environment:
      ENV: svt

I don’t believe that the workflows section supports environment var declarations, see the reference.

However, what you can do is declare a YAML block for the job (outside of the main structure) and then two jobs in which the environment section` is overwritten by a per-job value. I’m only vaguely familiar with this, but Wikipedia’s article on YAML gives details on how YAML parsing is meant to work here.

1 Like

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