Search code examples
pythonazure-devopspython-poetry

How to publish to an Azure Devops PyPI feed with Poetry?


I am trying to set up Azure Devops to publish to a PyPI feed with Poetry.

I know about Twine authentication and storing credentials to an Azure Key Vault. But is there any more straightforward method? Something like this:

- script: |
    source .venv/bin/activate
    poetry build
  displayName: Build wheel
- script: |
    source .venv/bin/activate
    poetry publish -u USER -p PASS
  displayName: Publish wheel

Solution

  • Yes. In the Azure DevOps web interface:

    1. Create a new PyPI feed (Artifacts > New feed > Create).
    2. Create PyPI credentials (Connect to feed > Python > Generate Python credentials).
    3. Create secret pipeline variables named username and password and valued with the PyPI credentials (Pipelines > Edit > Variables > New variable > Keep this value secret > OK).
    4. Update the contents of the azure-pipelines.yml CI file with this:
    trigger:
    - master
    
    pool:
      vmImage: ubuntu-latest
    
    steps:
    - task: UsePythonVersion@0
      inputs:
        versionSpec: 3.7
      displayName: Install Python
    - script: |
        python -m pip install -U pip
        pip install poetry
        poetry install
      displayName: Install software
    - script: |
        poetry run python -m unittest discover tests/ -v
      displayName: Test software
    - script: |
        poetry build
      displayName: Package software
    - script: |
        poetry config repositories.azure https://pkgs.dev.azure.com/{your organization}/_packaging/{your feed}/pypi/upload
        poetry config http-basic.azure $(username) $(password)
        poetry publish -r azure
        exit 0
      displayName: Publish software