GitLabCI:Yarn
lastmod 2025-02-14created 2022-11-1813 edits
How to apply GitLabCI for yarn.
Turns out yarn is already installed in the node:18 image.
Yarn Deploy
- Publish packages with Yarn | GitLab
- (Bug): Yarn 2 has broken scoped authentication functionality since 2.2.0 version · Issue #3541 · yarnpkg/berry
When deploying directly from GitLab CI, add the following to the .yarnrc.yml file.
nodeLinker: node-modules
yarnPath: .yarn/releases/yarn-3.4.1.cjs
npmScopes:
bogonets-steel:
npmPublishRegistry: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/npm/"
npmAlwaysAuth: true
npmAuthToken: "${CI_JOB_TOKEN}"
Then publish with one of the following commands.
- Yarn v1:
yarn publish - Yarn v2+:
yarn npm publish
You must publish with Yarn v2+ to be able to download the package with yarn berry.
Resolving .yarnrc.yml conflicts
If you use the file above directly, environment variable problems occur during normal use:
Usage Error: Environment variable not found (CI_API_V4_URL) in /home/user/Project/charging/.yarnrc.yml (in /home/user/Project/charging/.yarnrc.yml)
━━━ Yarn Package Manager - 3.4.1 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
$ yarn <command>
You can also print more details about any of these commands by calling them with
the `-h,--help` flag right after the command name.
You can change the .yarnrc.yml file name directly with the YARN_RC_FILENAME environment variable.
example:
Yarn Install
How to download a Gitlab npm package registered in a private registry:
| INFORMATION |
| When publishing, you must publish with Yarn v2+ ( |
If the npm package has a scope, add the scope's registry information to the .yarnrc.yml file:
nodeLinker: node-modules
yarnPath: .yarn/releases/yarn-3.4.1.cjs
npmScopes:
bogonets-steel:
npmRegistryServer: "https://git.bogohitec.com/api/v4/packages/npm"
# 아래 코드는 실패한 케이스
#npmRegistries:
# //git.bogohitec.com/api/v4/projects/123/packages/npm:
# npmAlwaysAuth: true
# npmAuthToken: 7Wo5YPC9zsCqrTsZ1tga
npmRegistries:
//git.bogohitec.com/api/v4/packages/npm:
npmAlwaysAuth: true
npmAuthToken: 7Wo5YPC9zsCqrTsZ1tga
Then just run yarn install.
Example
.yarnrc-ci.yml:
nodeLinker: node-modules
yarnPath: .yarn/releases/yarn-3.4.1.cjs
npmScopes:
bogonets-steel:
npmPublishRegistry: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/npm/"
npmAlwaysAuth: true
npmAuthToken: "${CI_JOB_TOKEN}"
.gitlab-ci.yml:
image: node:18
cache:
paths:
- .yarn
stages:
- test
- deploy
lint_and_test:
stage: test
cache:
paths:
- .yarn
before_script:
- yarn install
script:
- yarn lint
- yarn test
build_and_deploy:
stage: deploy
cache:
paths:
- .yarn
rules:
- if: $CI_COMMIT_REF_NAME == "release"
before_script:
- yarn install
script:
- yarn build
- yarn decl
- YARN_RC_FILENAME=.yarnrc-ci.yml yarn npm publish