Package: Python Twine Upload Authenticate

Version 1.* | Other versions

Azure Pipelines

Provides twine credentials to a PYPIRC_PATH environment variable for the scope of the build. This enables you to publish Python packages to feeds with twine from your build.

Note

The Python Twine Upload Authenticate task in Azure Pipelines is currently in public preview.

YAML snippet

# Python twine upload authenticate V1
# Authenticate for uploading Python distributions using twine. Add '-r FeedName/EndpointName --config-file $(PYPIRC_PATH)' to your twine upload command. For feed present in this organization, use the feed name as the repository (-r). Otherwise, use the endpoint name defined in the service connection.
- task: TwineAuthenticate@1
  inputs:
    #artifactFeed: MyTestFeed # Optional
    #pythonUploadServiceConnection: OtherOrganizationFeed # Optional

Arguments

Argument Description
artifactFeed
My feed (select below)
(Optional) An Azure Artifacts feed name to authenticate with twine.
pythonUploadServiceConnection
Feed from external organizations
(Optional) A twine service connection name from external organization to authenticate with twine. The credentials stored in the endpoint must have package upload permissions.
Control options

Examples

Publish python distribution to Azure Artifacts feed

In this example, we are setting authentication for publishing to a private Azure Artifacts Feed. The authenticate task creates a .pypirc file which contains the auth credentials required to publish a distribution to the feed.

# Install python distributions like wheel, twine etc
- script: |
   pip install wheel
   pip install twine
  
# Build the python distribution from source
- script: |
   python setup.py bdist_wheel
   
- task: TwineAuthenticate@1
  displayName: 'Twine Authenticate'
  inputs:
    # In this case, name of the feed is 'myTestFeed'
    artifactFeed: myTestFeed
  
# Use command line script to 'twine upload', use -r to pass the repository name and --config-file to pass the environment variable set by the authenticate task.
- script: |
   python -m twine upload -r "myTestFeed" --config-file $(PYPIRC_PATH) dist/*.whl

Publish python distribution to official python registry

In this example, we are setting authentication for publishing to official python registry. Create a twine service connection entry for pypi. The authenticate task uses that service connection to create a .pypirc file which contains the auth credentials required to publish the distribution.

# Install python distributions like wheel, twine etc
- script: |
   pip install wheel
   pip install twine
  
# Build the python distribution from source
- script: |
   python setup.py bdist_wheel
   
- task: TwineAuthenticate@1
  displayName: 'Twine Authenticate'
  inputs:
    # In this case, name of the service connection is "pypitest".
    pythonUploadServiceConnection: pypitest
  
# Use command line script to 'twine upload', use -r to pass the repository name and --config-file to pass the environment variable set by the authenticate task.
- script: |
   python -m twine upload -r "pypitest" --config-file $(PYPIRC_PATH) dist/*.whl

Task versions

Task: Twine Authenticate

Task version Azure Pipelines TFS
1.* Available Not supported
0.* Available Not supported

Open source

This task is open source on GitHub. Feedback and contributions are welcome.

Q & A

When in my pipeline should I run this task?

This task must run before you use twine to upload python distributions to an authenticated package source such as Azure Artifacts. There are no other ordering requirements. Multiple invocation of this task will not stack credentials. Every run of the task will erase any previously stored credentials.

My agent is behind a web proxy. Will TwineAuthenticate set up twine to use my proxy?

No. While this task itself will work behind a web proxy your agent has been configured to use, it does not configure twine to use the proxy.