'Set yarn environment variables without using terminal directly

We have a CI/CD pipeline that executes yarn install. I want to execute DOWNLOAD=1 yarn install command without modifying the current pipeline. I'm wondering if there's a way to tell yarn to do so by using package.json/.yarnrc.yml files. There's also preinstall hook where I've tried DOWNLOAD=1 yarn install but will lead to an endless loop.

Using terminal directly won't do it since I don't have access to the container.

Edit: I'm using yarn version 1.22.10 on my local machine, and 1.22.5 on the remote one.



Solution 1:[1]

.yarnrc.yml is only supported for Yarn 2.0 or later. You have to change the file and its syntax to .yarnrc. This later version of yarn also won't fallback for .npmrc.

Is it possible to set a global environment variable for this pipeline? E.g. add export DOWNLOAD=1 to your bash profile. Almost all providers support custom environment variables.

After you set up the variable, you can interpolate it in .yarnrc.yml (if you update yarn) as ${DOWNLOAD} as you've probably done already, but on yarn 1.X it needs to be provided in the CLI.

Alternatively, you can use .npmrc, which will accept environment variables, and yarn 1.X will fallback to it if it doesn't find the property in its own config.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Rafael Wendel