Search code examples
azureazure-devopsazure-pipelinesazure-artifacts

Installing packages from Azure DevOps Artifact Feed in a Azure Pipeline


I have two repositories.

  • The first is built by AzureDevOps Pipelines into a whl file and published on a Azure DevOps Artifact feed. (works)
  • The second should also be built by AzureDevOps Pipelines and published on Azure DevOps artifacts -> but it is dependend on the first one and needs to install it from the AzureDevops Artifact feed during the build-process. (this does not work).

I can install it locally, but the pipeline of the second package fails. When the pipeline fails, I get the following error:

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>

---------------------------------- SETUP ----------------------------------

I added the feed as a secondary source to the pyproject.toml of my second repository, this allows me to successfully install the first package with poetry add <firstpackage> and poetry install for my local IDE:

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

YAML script to install packages via poetry - works for the first repository, but not for the second repository which needs to install the first package from the Azure DevOps artifcats feed (the first installs everything from 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 script to publish a package to an Azure DevOps artifact feed (with a personal access token as authentification) - 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

Solution

  • Turns out, I just needed to configure poetry in the pipeline before the install for the second repository - same as I did locally, some long time ago (and forgot about it).

    - 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