Context env vars not being picked up inside commands

According to the docs you should specify what contexts you want to use at Workflow level, which makes sense, so lets assume I have something like this:

version: 2.1

commands:    
  build:
    description: Does an NPM build
    steps:
      - run: env
      - run: npm run build

executors:
  node-executor:
    docker:
      - image: circleci/node:12.14.1

jobs:
  build-app:
    executor: node-executor
    environment:
      TZ: 'Europe/London'
    steps:
      - build

workflows:
  version: 2
  build_stuff:
    jobs:      
      - build-app:
          context:
            - MyContext

So in this case I would expect the environmental vars that are in MyContext to be passed into the job build-app which in turn calls build command, and we are seeing that in SSH the context environmental vars have been set, but when we run the comman (build) they are no longer available.

So do you need to do anything else to have commands take the env vars from the job thats calling them?

1 Like

This example you have looks correct. If the command doesn’t read the env var, my guess would be that it’s the command that’s set up incorrectly instead of the env var.