Skip to content
Snippets Groups Projects
Commit 7e4ca313 authored by Clément Contet's avatar Clément Contet Committed by Pierre Smeyers
Browse files

feat: add support for NPM scoped registries authentication

parent 9fa7a539
No related branches found
No related tags found
No related merge requests found
......@@ -26,6 +26,23 @@ The Angular template uses some global configuration used throughout all jobs.
| `NG_WORKSPACE_DIR` | Angular workspace directory | `.` |
| `NG_INSTALL_EXTRA_OPTS`| Extra options to install project dependencies (with [`npm ci`](https://docs.npmjs.com/cli/ci.html/)) | _none_ |
### Configuring scoped registries
You may configure [scoped registries](https://docs.npmjs.com/cli/v8/using-npm/scope#associating-a-scope-with-a-registry) with the `$NPM_CONFIG_SCOPED_REGISTRIES` variable.
The value is expected as a (whitespace-separated) list of `@registry_scope:registry_url`.
The Angular template also supports authentication tokens for each, simply by defining `NPM_REGISTRY_<SCOPE>_AUTH` (as project or group secret variables).
:warning: The `<SCOPE>` part is the `registry_scope` transformed in [SCREAMING_SNAKE_CASE](https://en.wikipedia.org/wiki/Snake_case) (uppercase words separated by underscores).
Example: declare the GitLab chart repository from another GitLab project
```yml
variables:
NPM_CONFIG_SCOPED_REGISTRIES: "@public-repo:https://public.npm.registry/some/repo @priv-repo:https://private.npm.registry/another/repo"
# NPM_REGISTRY_PRIV_REPO_AUTH set as a project secret variables
```
## Jobs
### `ng-lint` job
......
......@@ -445,7 +445,16 @@ stages:
then
for scoped_registry in $NPM_CONFIG_SCOPED_REGISTRIES
do
npm config set "${scoped_registry%%:*}":registry "${scoped_registry#*:}";
reg_scope=${scoped_registry%%:*}
reg_url=${scoped_registry#*:}
npm config set "${reg_scope}:registry" "${reg_url}"
reg_scope_ssc=$(echo "$reg_scope" | tr '[:lower:]' '[:upper:]' | tr -d '@' | tr '[:punct:]' '_')
reg_auth=$(eval echo "\$NPM_REGISTRY_${reg_scope_ssc}_AUTH")
if [[ "${reg_auth}" ]]
then
reg_url_no_proto=${reg_url#*:}
npm config set "${reg_url_no_proto}:_authToken" "${reg_auth}"
fi
done
fi
- configure_gitlab_instance_level_npm_registry_auth
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment