Using npm login on CircleCI
npm to install a private module in a continuous integration
environment for the first time, a brick wall is quickly hit. The
command is designed to be used interactively. This causes an issue in CI,
scripts, etc. Here’s how to use
npm login on CircleCI.
Step 1 - Private Environment Variables
For reusability, we can set
npm login info in environment variables (envar).
While we can set envars in
circle.yml, this will appear in Git and thus
be public. Instead, we can use private envars via CircleCI.com or the API.
The following variables should be set (variable names can be changed, just stay consistent):
Step 2 - The Actual Login Request
Various workarounds to get
npm login working exists. Here is a
fairly simple method that can be done in
dependencies: pre: - echo -e "$NPM_USER\n$NPM_PASS\n$NPM_EMAIL" | npm login