在CircleCI中安装GitHub软件包

对于我的项目,我正在尝试从GitHub Packages安装(而不是发布!)npm软件包。它托管在组织中的私有存储库中。我已经制作了一个具有所需权限的个人访问令牌,可以从该存储库和组织中进行读取。所有这些操作在本地运行都可以通过以下步骤进行:

  • .npmrc文件中设置注册表:registry=https://npm.pkg.github.com/OWNER
  • 终端登录:npm login --registry=https://npm.pkg.github.com 然后它将提示:
> username: username
> Password: TOKEN
> Email: PUBLIC-EMAIL-ADDRESS
  • username是您的标准github用户名
  • Token是具有正确权限创建的个人访问令牌
  • Email可以是随机的

填写后,一切正常,我可以安装packge以及正常npm注册表中托管的所有其他软件包。 现在解决问题:我正在尝试在circleCI上复制相同内容,但似乎没有让我覆盖npm注册表。项目在.npmrc所在的同一文件夹中包含一个package.json文件。这是圈子ci conf的一部分:

      - run:
          name: "Set NPM registry"
          command: npm config set registry https://npm.pkg.github.com/OWNER
      - run:
          name: "Authenticate with GitHub package registry"
          command: echo "//npm.pkg.github.com/:_authToken=${GITHUB_PACKAGES}" > web_ui/frontend/.npmrc
      - run:
          name: "Install frontend dependencies"
          command: npm run deps-frontend

GITHUB_PACKAGES只是存储在circleCI中的一个env变量。

现在错误消息告诉我以下内容:

npm ERR! code E401
npm ERR! Unable to authenticate,need: Basic realm="GitHub Package Registry"

我尝试使用谷歌搜索,但没有任何结果。

mmtsky 回答:在CircleCI中安装GitHub软件包

您可以尝试在run步骤中移动pre步骤吗?像这样:

pre:
  - npm config set registry https://npm.pkg.github.com/OWNER
  - echo "//npm.pkg.github.com/:_authToken=${GITHUB_PACKAGES}" > web_ui/frontend/.npmrc
  - npm run deps-frontend

另一种尝试是使用其他版本的npm

,

创建用于设置 .npmrc 值的命令,请参阅 orb 源 npm-config/set-registry

使用示例:

 steps:
  - checkout
  - npm-config/set-registry:
      registry-prurl: //your.registry.domain.net/path/
      scope: '@your-scope'
      auth-token: your-repo-token
  - run:
      name: Download depencies
      command: yarn

来源:

set-registry:
description: Sets a registry to .npmrc
parameters:
  registry-prurl:
    description: |
      protocol-relative URL (ex: //registry.domain.net/path/)
    type: string
  scope:
    description: registry scope
    type: string
  auth-token:
    description: authorization token for private repos
    type: string
    default: ""
steps:
  - run:
      name: Set NPM registry URL
      command: >
        scope=<< parameters.scope >>;
        registry_prurl=<< parameters.registry-prurl >>;
        npm config set "${scope}:registry" "https:$registry_prurl"
  - run:
      name: Set auth token for NPM registry if provided
      command: |
        if [ "<< parameters.auth-token >>" != "" ]; then
        registry_prurl=<< parameters.registry-prurl >>;
        auth_token=<< parameters.auth-token >>;
        echo "${registry_prurl}:_authToken=${auth_token}" >> ~/.npmrc
        fi;
本文链接:https://www.f2er.com/2964155.html

大家都在问