Skip to content

Commit 76a8753

Browse files
Manuel GrabowskiRussell Dickenson
Manuel Grabowski
authored and
Russell Dickenson
committed
Clarify npm package publishing via CI/CD
1 parent 732a0aa commit 76a8753

File tree

2 files changed

+10
-19
lines changed

2 files changed

+10
-19
lines changed

Diff for: doc/user/packages/npm_registry/index.md

+9-18
Original file line numberDiff line numberDiff line change
@@ -83,38 +83,29 @@ NPM_TOKEN=your_token npm publish
8383

8484
Your package should now publish to the Package Registry.
8585

86-
## Publishing a package via a CI/CD pipeline
86+
## Publishing a package by using a CI/CD pipeline
8787

88-
### Authenticating via the `.npmrc`
89-
90-
Create or edit the `.npmrc` file in the same directory as your `package.json` in a GitLab project. Include the following lines in the `.npmrc` file:
88+
When publishing by using a CI/CD pipeline, you can use the [predefined variables](../../../ci/variables/predefined_variables.md) `${CI_PROJECT_ID}` and `${CI_JOB_TOKEN}` to authenticate with your project's Package Registry. We use these variables to create a `.npmrc` file [for authentication](#authenticating-via-the-npmrc) during execution of your CI/CD job.
9189

92-
```shell
93-
@scope:registry=https://your_domain_name/api/v4/projects/your_project_id/packages/npm/
94-
//your_domain_name/api/v4/projects/${CI_PROJECT_ID}/packages/npm/:_authToken=${CI_JOB_TOKEN}
95-
```
96-
97-
- Replace `@scope` with the [root level group](#naming-convention) of the project you're publishing to the package to.
98-
- The `${CI_PROJECT_ID}` and `${CI_JOB_TOKEN}` are [predefined variables](../../../ci/variables/predefined_variables.md) that are available in the pipeline and do not need to be replaced.
99-
100-
### Publishing a package via a CI/CD pipeline
101-
102-
In the GitLab project that houses your `.npmrc` and `package.json`, edit or create a `.gitlab-ci.yml` file. For example:
90+
In the GitLab project containing your `package.json`, edit or create a `.gitlab-ci.yml` file. For example:
10391

10492
```yaml
10593
image: node:latest
10694

10795
stages:
10896
- deploy
10997

110-
deploy:
98+
publish-npm:
11199
stage: deploy
112100
script:
113-
- echo "//${CI_SERVER_HOST}/api/v4/projects/${CI_PROJECT_ID}/packages/npm/:_authToken=${CI_JOB_TOKEN}">.npmrc
101+
- echo "@scope:registry=https://${CI_SERVER_HOST}:${CI_SERVER_PORT}/api/v4/projects/${CI_PROJECT_ID}/packages/npm/" > .npmrc
102+
- echo "//${CI_SERVER_HOST}:${CI_SERVER_PORT}/api/v4/projects/${CI_PROJECT_ID}/packages/npm/:_authToken=${CI_JOB_TOKEN}" >> .npmrc
114103
- npm publish
115104
```
116105
117-
Your package should now publish to the Package Registry when the pipeline runs.
106+
- Replace `@scope` with the [scope](https://docs.npmjs.com/cli/v10/using-npm/scope) of the package that is being published.
107+
108+
Your package is published to the Package Registry when the `publish-npm` job in your pipeline runs.
118109

119110
## Install a package
120111

Diff for: doc/user/packages/package_registry/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ For more information about using the GitLab Package Registry with CI/CD, see:
8989
- [Conan](../conan_repository/index.md#publish-a-conan-package-by-using-cicd)
9090
- [Generic](../generic_packages/index.md#publish-a-generic-package-by-using-cicd)
9191
- [Maven](../maven_repository/index.md#create-maven-packages-with-gitlab-cicd)
92-
- [npm](../npm_registry/index.md#publishing-a-package-via-a-cicd-pipeline)
92+
- [npm](../npm_registry/index.md#publishing-a-package-by-using-a-cicd-pipeline)
9393
- [NuGet](../nuget_repository/index.md#publish-a-nuget-package-by-using-cicd)
9494
- [PyPI](../pypi_repository/index.md#authenticate-with-a-ci-job-token)
9595
- [RubyGems](../rubygems_registry/index.md#authenticate-with-a-ci-job-token)

0 commit comments

Comments
 (0)