0

I've created a public npm repository: https://www.npmjs.com/package/point-cloud-visualiser

I'm trying to run npm publish from within codebuild. I have generated a token and saved it in AWS secrets manager. I am succesfully pulling the secret in the buildspec. However I am unsure how to configure the .npmrc file so that it uses the token and doesn't tell me to login.

Currently my .npmrc looks like this:

@point-cloud-visualiser:registry=https://www.npmjs.com/package/point-cloud-visualiser
//point-cloud-visualiser/:_authToken=${NPM_TOKEN}

And my buildspec.yml looks like this:

version: 0.2

env:
  secrets-manager:
    NPM_TOKEN: "npm-token:npm-token"

phases:
  install:
    commands:
      - npm install
  build:
    commands:
      - npm run build
      - npm publish

But when it fails on npm publish giving the error:

npm ERR! code ENEEDAUTH
npm ERR! need auth This command requires you to be logged in to https://registry.npmjs.org/
npm ERR! need auth You need to authorize this machine using `npm adduser`

I have also tried removing the .npmrc file and using the following in the buildspec.yml:

version: 0.2

env:
  secrets-manager:
    NPM_TOKEN: "npm-token:npm-token"

phases:
  install:
    commands:
      - npm install
  build:
    commands:
      - npm run build
      - npm config set registry 'https://www.npmjs.com/package/point-cloud-visualiser'
      - npm config set '//npmjs.com/package/point-cloud-visualiser/:always-auth' 'true'
      - npm config set '//npmjs.com/package/point-cloud-visualiser/:_authToken' '${NPM_TOKEN}'
      - npm publish

But this approach gives the same result as above. What am I doing wrong? Thank you!

Mark
  • 136
  • 9

1 Answers1

0

The following buildspec worked succesfully:

version: 0.2

env:
  secrets-manager:
    NPM_TOKEN: "npm-token:npm-token"

phases:
  install:
    commands:
      - npm install
  build:
    commands:
      - npm run build
      - echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/.npmrc
      - echo "//registry.npmjs.org/:always-auth=true" >> ~/.npmrc
      - npm publish
Mark
  • 136
  • 9