diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-14 21:07:45 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-14 21:07:45 +0000 |
commit | 0b12a5312c9701fbfed25fbb334d47900ced736b (patch) | |
tree | a29a27e297134f573fd8e5c298d241f3156c207a /doc/user/packages | |
parent | 92f95ccac81911d1fcc32e999a7f1ce04624a56c (diff) | |
download | gitlab-ce-0b12a5312c9701fbfed25fbb334d47900ced736b.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'doc/user/packages')
-rw-r--r-- | doc/user/packages/npm_registry/index.md | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/doc/user/packages/npm_registry/index.md b/doc/user/packages/npm_registry/index.md index 6b65aaba2c5..5fdbbcedfc9 100644 --- a/doc/user/packages/npm_registry/index.md +++ b/doc/user/packages/npm_registry/index.md @@ -73,20 +73,20 @@ If you have 2FA enabled, you need to use a [personal access token](../../profile ### Authenticating with an OAuth token To authenticate with an [OAuth token](../../../api/oauth2.md#resource-owner-password-credentials-flow) -or [personal access token](../../profile/personal_access_tokens.md), add a corresponding section to your `.npmrc` file: +or [personal access token](../../profile/personal_access_tokens.md), set your NPM configuration: -```ini -; Set URL for your scoped packages. -; For example package with name `@foo/bar` will use this URL for download -@foo:registry=https://gitlab.com/api/v4/packages/npm/ +```bash +# Set URL for your scoped packages. +# For example package with name `@foo/bar` will use this URL for download +npm config set @foo:registry https://gitlab.com/api/v4/packages/npm/ -; Add the token for the scoped packages URL. This will allow you to download -; `@foo/` packages from private projects. -//gitlab.com/api/v4/packages/npm/:_authToken=<your_token> +# Add the token for the scoped packages URL. This will allow you to download +# `@foo/` packages from private projects. +npm config set '//gitlab.com/api/v4/projects/<your_project_id>/packages/npm/:_authToken' "<your_token>" -; Add token for uploading to the registry. Replace <your_project_id> -; with the project you want your package to be uploaded to. -//gitlab.com/api/v4/projects/<your_project_id>/packages/npm/:_authToken=<your_token> +# Add token for uploading to the registry. Replace <your_project_id> +# with the project you want your package to be uploaded to. +npm config set '//gitlab.com/api/v4/packages/npm/:_authToken' "<your_token>" ``` Replace `<your_project_id>` with your project ID which can be found on the home page @@ -103,13 +103,11 @@ If you encounter an error message with [Yarn](https://yarnpkg.com/en/), see the ### Using variables to avoid hard-coding auth token values -To avoid hard-coding the `authToken` value, you may use a variables in its place. -In your `.npmrc` file, you would add: +To avoid hard-coding the `authToken` value, you may use a variables in its place: -```ini -@foo:registry=https://gitlab.com/api/v4/packages/npm/ -//gitlab.com/api/v4/packages/npm/:_authToken=${NPM_TOKEN} -//gitlab.com/api/v4/projects/<your_project_id>/packages/npm/:_authToken=${NPM_TOKEN} +```bash +npm config set '//gitlab.com/api/v4/projects/<your_project_id>/packages/npm/:_authToken' "${NPM_TOKEN}" +npm config set '//gitlab.com/api/v4/packages/npm/:_authToken' "${NPM_TOKEN}" ``` Then, you could run `npm publish` either locally or via GitLab CI/CD: @@ -227,6 +225,14 @@ And the `.npmrc` file should look like: @foo:registry=https://gitlab.com/api/v4/packages/npm/ ``` +### `npm install` returns `Error: Failed to replace env in config: ${NPM_TOKEN}` + +You do not need a token to run `npm install` unless your project is private (the token is only required to publish). If the `.npmrc` file was checked in with a reference to `$NPM_TOKEN`, you can remove it. If you prefer to leave the reference in, you'll need to set a value prior to running `npm install` or set the value using [GitLab environment variables](./../../../ci/variables/README.md): + +```bash +NPM_TOKEN=<your_token> npm install +``` + ## NPM dependencies metadata > [Introduced](https://gitlab.com/gitlab-org/gitlab/issues/11867) in GitLab Premium 12.6. |