Override ENV variable of docker image (Circleci 2.0)

docker
yarn

#1

The docker image circleci/node:8 exposes the environment variable YARN_VERSION to set a specific yarn version. When I set the version in the environment map, it’s not picked up by the docker image:

version: 2
jobs:
build:
docker:
- image: circleci/node:8
environment:
YARN_VERSION: 1.9.4
steps:
- run: echo $YARN_VERSION
- run: yarn --version

Outputs:

====>> echo $YARN_VERSION
#!/bin/bash -eo pipefail
echo $YARN_VERSION
1.9.4
====>> yarn --version
#!/bin/bash -eo pipefail
yarn --version
1.6.0

The question is how to pass the environment variable to docker?


#2

So I am mistaking build environments vs runtime environments. So please ignore this post.


#3

Tips:

  • You may be able to delete the post, using the toolbar under the first post.
  • When presenting YAML, please use a code block, not a quote block. Quote blocks collapse space indentation, which means readers cannot see the structure of your YAML.

#4

Thanks for the tips. The ui says I don’t have permissions to remove the post (that’s why I replied to my own post).


#5

@tkvw Can you clarify the final solution by providing your updated YML config?


#6

@rtymchyk: it’s more of a conceptual understanding than a solution. The image is build using a specific YARN_VERSION, so altering the yarn version doesn’t do much. There are two things you can do:
create a custom docker image or create a run command script which downloads yarn and cache this.

The latter is some work, but should be straight forward (you can copy the commands from the node js dockerfile).


#7

Makes sense. Thanks for the reply.


#8

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