0

I have a jenkins job trying to push a a npm package to a private aws code-artifact repo.

This works locally on my machine however when run through jenkins this errors out. The jenkins setup is to run a container as a slave with node installed in it. This is the only difference I can spot from my laptop.

Here's the build log: https://pastebin.com/fENQSG9w

+ cat -A /home/jenkins/.npmrc
registry=https://myorg-awsAccNo.d.codeartifact.us-east-1.amazonaws.com/npm/myrepo/$
//myorg-awsAccNo.d.codeartifact.us-east-1.amazonaws.com/npm/myrepo/:always-auth=true$
//myorg-awsAccNo.d.codeartifact.us-east-1.amazonaws.com/npm/myrepo/:_authToken=eyJ2ZXIiXXXXXXXXXxx2h99mC5RQp4El-0g$
+ cat -A .npmrc
cat: .npmrc: No such file or directory

I see that the aws cli to login works, it setups the .npmrc on the user level with the auth token as well. However when it comes to publishing the artifact it goes to https://registry.npmjs.org/@myscope%2ftest-poc-package and not the npm code-artifact location.

npm version inside the slave container is : 6.14.11

I have added steps in the jenkins job to list the .npmrc inside the user home and the project home as well as the npm debug log and none of it indicates anything out of the ordinary.

Yogesh_D
  • 17,656
  • 10
  • 41
  • 55

1 Answers1

0

I could not get this to work in my setup. Eventually ended up doing this in my Jenkins file. In the env section get the Artifact auth token:

environment {
        CODEARTIFACT_AUTH_TOKEN = sh(script: "aws codeartifact get-authorization-token --duration-seconds 0 --domain mydomain --domain-owner xxxxxxxx --query authorizationToken --output text --endpoint-url https://vpce-xxxxxxx-xxxxxxx.api.codeartifact.us-east-1.vpce.amazonaws.com" , returnStdout: true).trim()
    }

And then adding this as a part of the build steps

stage('Build and Publish'){
  steps{
        sh '''
            npm config set registry 'https://mydomain-xxxxxxxxx.d.codeartifact.us-east-1.amazonaws.com/npm/myrepo/'
            npm config set '//mydomain-xxxxxxxxx.d.codeartifact.us-east-1.amazonaws.com/npm/myrepo/:always-auth' 'true'
            npm config set '//mydomain-xxxxxxxxx.d.codeartifact.us-east-1.amazonaws.com/npm/myrepo/:_authToken' '${CODEARTIFACT_AUTH_TOKEN}'
        '''
        sh  'npm run build'
        sh  'npm publish'
      }
  }

This helped setup the repo and its token and I was able to get npm to use the AWS CodeArtifact as the repo.

Yogesh_D
  • 17,656
  • 10
  • 41
  • 55