Commit b4cda2e8 authored by Jamie Tanna's avatar Jamie Tanna
Browse files

Blogument NPM publishing with GitLab CI

parent 9a91095b
Pipeline #435780665 passed with stages
in 5 minutes and 23 seconds
title: "Publishing a NPM Package to from GitLab CI"
description: "How to publish an NPM package to the public NPM registry, using GitLab CI."
- blogumentation
- nodejs
- gitlab-ci
license_code: Apache-2.0
license_prose: CC-BY-NC-SA-4.0
date: 2021-12-23T11:01:55+0000
slug: "gitlab-ci-npm-publish"
image: /img/vendor/nodejs.png
To be able to more easily release packages to the NPM registry, we likely want to have our CI/CD process publish packages on tagged versions.
As I use GitLab CI for personal projects, I wanted to set this up, and through a mix of [Eleanor Holley's article]( and a bit of brute force, I've managed to be happy with the following setup:
image: node:16
- test
- publish
- node_modules/
- npm ci
- npm run lint
- npm run test
# any other steps
stage: publish
- tags
- npm run ci-publish
Now, the biggest gotcha I had was that my `NPM_TOKEN` wasn't being registered, and so CI builds were failing with:
<summary>Example <code>ENEEDAUTH</code> errors</summary>
npm ERR! need auth This command requires you to be logged in.
npm ERR! need auth You need to authorize this machine using `npm adduser`
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2021-12-23T09_49_35_606Z-debug.log
I'd thought it was the way I was doing it (by editing the `.npmrc`) so I moved over to `ci-publish`, but it turns out it was because GitLab CI's protected mode for CI/CD variables requires the _tags_ to have protection, too.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment