DEV Community

Discussion on: Gitlab CI/CD for npm packages

Collapse
 
rtorcato profile image
Richard Torcato • Edited

you can add this script to the top of your file that will run before each stage. Then remove - .npmrc in each stage. Also don't call docker. Just call node directly now that it's set as the default.

default:
image: node:latest
before_script:
- npm ci --cache .npm --prefer-offline
- |
{
echo "@${CI_PROJECT_ROOT_NAMESPACE}:registry=${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/npm/"
echo "${CI_API_V4_URL#https?}/projects/${CI_PROJECT_ID}/packages/npm/:_authToken=\${CI_JOB_TOKEN}"
} | tee --append .npmrc
cache:
key: ${CI_COMMIT_REF_SLUG}
paths:
- .npm/

Collapse
 
stevemoretz profile image
Steve Moretz

Those are good points, but he already mentioned I didn't have a gitlab runner that was setup to use docker normally nor did I have node and npm installed on the machine so I had to use docker run commands like shown. So... not the most elegant way of doing it.