簡體   English   中英

在 Azure 管道中安裝來自 Azure DevOps Artifact Feed 的包

[英]Installing packages from Azure DevOps Artifact Feed in a Azure Pipeline

我有兩個存儲庫。

  • 第一個由 AzureDevOps Pipelines 構建成 whl 文件並發布在 Azure DevOps Artifact 提要上。 (作品)
  • 第二個也應該由 AzureDevOps Pipelines 構建並發布在 Azure DevOps artifacts -> 但它依賴於第一個並且需要在構建過程中從 AzureDevops Artifact feed 安裝它。 (這不起作用)。

我本地可以安裝,但是第二個package的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中,這使我能夠成功安裝第一個 package,並為我的本地 IDE 安裝poetry add <firstpackage>poetry install

[[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 提要安裝第一個 package 的第二個存儲庫(第一個安裝來自 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

YAML 腳本將 package 發布到 Azure DevOps 工件提要(使用個人訪問令牌作為身份驗證)-有效

- 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

我沒有將我的個人訪問令牌 (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.*/\1/')
      poetry config http-basic.azure build "$PAT"
      poetry install
    displayName: "Install dependencies"

事實證明,我只需要在安裝第二個存儲庫之前在管道中配置 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM