【问题标题】:Installing a GitHub Package in CircleCI在 CircleCI 中安装 GitHub 包
【发布时间】:2019-12-06 09:15:40
【问题描述】:

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

  • .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 可以是随机的

填写完成后,一切正常,我可以安装包,以及托管在正常 npm 注册表上的所有其他包。 现在解决问题:我试图在 circleCI 上复制相同的内容,但它似乎不允许我覆盖 npm 注册表。该项目在package.json 所在的同一文件夹中包含一个.npmrc 文件。这是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 中的环境变量。

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

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

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

【问题讨论】:

    标签: github circleci circleci-2.0 github-package-registry


    【解决方案1】:

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

    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

    【讨论】:

    • 找不到文档,所以我真的不知道如何应用它
    • 哪种解决方案有效? npm 版本更改或pre 步骤?
    【解决方案2】:

    创建一个用于设置.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;
    

    【讨论】:

      猜你喜欢
      • 2015-08-16
      • 1970-01-01
      • 2016-04-18
      • 2019-07-03
      • 1970-01-01
      • 1970-01-01
      • 2016-04-27
      • 2021-03-06
      • 1970-01-01
      相关资源
      最近更新 更多