How I setup Semaphore CI to publish my NPM Package

Chai Phonbopit
Sep 5, 2018 · 3 min read

A couple week ago, I learned about how to setup Semaphore CI to automatically publish my NPM Package.

SemaphoreCI is the Continuous Integration service of choice for me (I used both my personal and company projects) In this post I just notes what I learned about how to setup for publishing an NPM Package.

I will skip a part about NPM and focus on SemaphoreCI Setting, I assume you already have NPM project and already to set up semaphore project

I want to publish my React and Redux Utils function to NPM Package.

And project on Semaphore here


Setup NPM Token

Before we publish to npmjs we need to login but for SemaphoreCI, we can’t logged in via browser or terminal, all we need is to use token from npmjs

I created token by go to https://www.npmjs.com and select Settings => Create new token

We use this token for publish to NPM

Next we need to setup Semaphore project to know about npm token that .npmrc contains a snippet code like this:

//registry.npmjs.org/:_authToken=MY_TOKEN

Then, I go to Project Setting => Configuration Files and then create a file name and paste a content.

We use Semaphore environment variable $NPM_TOKEN for NPM Token

Next step, We setup environment variable by assign MY_TOKEN to $NPM_TOKEN variable like this:


Set up Deployment

First step, I create deployment server with Generic deployment

Setup Deployment

Then, I chose Automatic because I want to let Semaphore will deploy every build.

And select master branch only for do this job (another branch just run a test don’t deploy)

For a script I just create 2 commands with:

npm build
npm publish --access=public
  • npm build : To create build version of library
  • npm publish Publish to NPM with public access (for scoped NPM)

And now, everything work as I expected. Done 🎉

Happy Coding ❤️

Today I Learned ❤️Chai

Chai's learning journey about Web development (Node.js + React), Lifestyle, Travel and Self Improvement.

Chai Phonbopit

Written by

I make web stuff with JavaScript (Node & React), Blogger at https://devahoy.com 🤖

Today I Learned ❤️Chai

Chai's learning journey about Web development (Node.js + React), Lifestyle, Travel and Self Improvement.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade