在 Azure 管道中从 Azure DevOps 工件源安装包

Installing packages from Azure DevOps Artifact Feed in a Azure Pipeline

我有两个存储库。

我可以在本地安装,但是第二个包的管道失败了。当管道失败时,我收到以下错误:

401 Client Error: Unauthorized for url: 
https://pkgs.dev.azure.com/<company>/<some-numbers>/_packaging/<some-numbers>/pypi/download/<mypackage>/0.0.1.9/<mypackage>-0.0.1.9-py3-none-any.whl#sha256=<some-numbers>

-------------------------------- 设置 ---------- ----------------------

我将提要作为第二个来源添加到我的第二个存储库的 pyproject.toml 中,这使我能够使用 poetry add <firstpackage> 成功安装第一个包poetry install 用于我的本地 IDE:

[[tool.poetry.source]]
name = "azure"
url = "https://pkgs.dev.azure.com/<company>/<some-numbers>/_packaging/<feed-name>/pypi/simple/"
secondary = true

通过诗歌安装包的YAML脚本-适用于第一个存储库,但不适用于第二个存储库需要安装来自 Azure DevOps artifcats feed 的第一个包(第一个安装来自 pypi.org 的所有内容):

- script: |
    python -m pip install -U pip
    pip install poetry==1.1.3  # Install poetry via pip to pin the version
    poetry install
  displayName: Install software

用于将程序包发布到 Azure DevOps 工件源的 YAML 脚本(使用个人访问令牌作为身份验证)- works:

- script: |
    poetry config repositories.azure https://pkgs.dev.azure.com/<company>/<somenumbers>/_packaging/<feed-name>/pypi/upload/
    poetry config http-basic.azure usernamedoesnotmatter $(pat)
    poetry publish --repository azure
    exit 0
  displayName: Publish package

事实证明,我只需要在安装第二个存储库之前在管道中配置 poetry - 就像很久以前我在本地所做的一样(后来忘记了)。

- script: |
    python -m pip install -U pip
    pip install poetry==1.1.3  # Install poetry via pip to pin the version
    
    # configuring the feed as a secondary source for poetry
    poetry config repositories.azure https://pkgs.dev.azure.com/<company>/<some-numbers>/_packaging/<feed-name>/pypi/simple/
    poetry config http-basic.azure userNameDoesntMatter $(pat)  

    poetry install    
    displayName: Install software

我没有将我的个人访问令牌 (PAT) 检查到我的存储库中。

pyproject.toml(部分):

[[tool.poetry.source]]
name = "azure"
url = "https://pkgs.dev.azure.com/<company>/<some-numbers>/_packaging/<feed-name>/pypi/simple/"
secondary = true

我添加了 PipAuthenticate@1 任务来设置包含 PAT 的 PIP_EXTRA_INDEX_URL 环境变量。在脚本中,我提取了PAT并用它来配置诗歌。

azure-pipelines.yaml(部分):

  - task: PipAuthenticate@1
    displayName: 'Pip Authenticate'
    inputs:
      artifactFeeds: '<some-numbers>/<feed-name>'
      onlyAddExtraIndex: True


  - script: |
      python -m pip install --upgrade pip
      pip install poetry
      export PAT=$(echo "$PIP_EXTRA_INDEX_URL" | sed 's/.*build:\(.*\)@pkgs.*//')
      poetry config http-basic.azure build "$PAT"
      poetry install
    displayName: "Install dependencies"