Publish Python packages with Azure Pipelines

Azure DevOps Services

Using Azure Pipelines, you can publish your Python packages to Azure Artifacts feeds, public registries, or as a pipeline artifacts.

This article will show you how to:

  • Install Twine
  • Authenticate with your Azure Artifacts feeds
  • Publish Python packages to an Azure Artifacts feed

Install twine

- script: 'pip install twine'

Authenticate with Azure Artifacts

To use twine to publish your Python packages, you must first set up authentication to you Azure Artifacts feed. The TwineAuthenticate task stores your credentials in a PYPIRC_PATH environment variable. twine will reference this variable to publish your packages from your pipeline.

- task: TwineAuthenticate@1
  inputs:
    artifactFeed: <PROJECT_NAME/FEED_NAME>                            #Provide the FeedName only if you are using an organization-scoped feed.
    pythonUploadServiceConnection: <NAME_OF_YOUR_SERVICE_CONNECTION>
  • artifactFeed: The name of your feed.
  • pythonUploadServiceConnection: a service connection to authenticate with twine.

Tip

The credentials stored in the PYPIRC_PATH environment variable supersede those in your .ini and .conf files.
If you add multiple TwineAuthenticate tasks at different stages in your pipeline, each additional task execution will extend (not override) the existing PYPIRC_PATH environment variable.

Publish Python packages to Azure Artifacts feeds

- script: |
     pip install wheel
     pip install twine
  
- script: |
     python setup.py bdist_wheel
   
- task: TwineAuthenticate@1
  displayName: Twine Authenticate
  inputs:
    artifactFeed: projectName/feedName        #Provide the FeedName only if you are using an organization-scoped feed.
  
- script: |
     python -m twine upload -r feedName --config-file $(PYPIRC_PATH) dist/*.whl