3

This question includes a specific use-case:

  1. I have a private scoped package: @myscope/mypackage
  2. It hosted in Artifactory NPM registry: https://company.jfrog.io/artifactory/api/npm/my-npm-registry/
  3. I need to use my credentials to consume it.
  4. I want to consume it in Github Actions.

How can I do that?

baruchiro
  • 5,088
  • 5
  • 44
  • 66

1 Answers1

7

.npmrc

First, you need to configure your access in a local .npmrc file. You can put this file in your source root folder.

always-auth = true

# First, set a different registry URL for your scope
@myscope:registry=https://company.jfrog.io/artifactory/api/npm/my-npm-registry/
# Then, for this scope, you need to set the token
//company.jfrog.io/artifactory/api/npm/my-npm-registry/:_auth = {{your token - see below}}

Token

You need to get the NPM Token from Artifactory (note it isn't your API Key.

  1. Get your Artifactory API Key from your Artifactory profile: https://company.jfrog.io/ui/admin/artifactory/user_profile
  2. Run the next command on your Linux terminal: curl -u {{ ARTIFACTORY_USERNAME }}:{{ ARTIFACTORY_API_KEY }} https://company.jfrog.io/artifactory/api/npm/auth/
    • Powershell:
      $base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f {{ ARTIFACTORY_USERNAME }},{{ ARTIFACTORY_API_KEY }})))
      Invoke-RestMethod -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} https://company.jfrog.io/artifactory/api/npm/auth/
      
  3. You should receive this:
    _auth = {{ YOUR_NPM_TOKEN }}
    always-auth = true
    
  4. So now you can take this Token and put it in the .npmrc file above.

Github Actions

How to do all this in Github Actions?

  1. First, save your Jfrog username and API Key in Github Secrets: JFROG_USER & JFROG_PAT.
  2. And you can add the next step to your workflow, after checkout and before yarn/npm install:
    - name: npm token
      run: |
        echo "@myscope:registry=https://company.jfrog.io/artifactory/api/npm/my-npm-registry/" > .npmrc
        echo "//company.jfrog.io/artifactory/api/npm/my-npm-registry/:$(curl -u ${{ secrets.JFROG_USER }}:${{ secrets.JFROG_PAT }} https://company.jfrog.io/artifactory/api/npm/auth/)" >> .npmrc
    
Dharman
  • 30,962
  • 25
  • 85
  • 135
baruchiro
  • 5,088
  • 5
  • 44
  • 66