简体   繁体   中英

How to install scoped private npm package from Artifactory in Github Actions

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?

.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

GOOD LUCK!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM