Publish Python packages with Azure Pipelines

With Azure Pipelines, you can publish your Python packages to Artifacts feeds, public registries, and within your Pipelines. This article will show you how to:

  • Install twine
  • Authenticate with your Azure Artifacts feed
  • Publish Python packages to your feed

Install twine

- script: 'pip install twine'

See script shortcut for more details.

Authenticate with Azure Artifacts

To use twine to publish your Python packages, you must first set up authentication. 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

Warning

Make sure you are not checking your credentials into source control.