Uredi

Deli z drugimi prek


TwineAuthenticate@1 - Python twine upload authenticate v1 task

Use this task to authenticate uploads of Python distributions using twine. Add -r FeedName/EndpointName --config-file $(PYPIRC_PATH) to your twine upload command. For feeds present in this organization, use the feed name as the repository (-r). Otherwise, use the endpoint name defined in the service connection.

Syntax

# 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 feeds 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:
  # Feeds and Authentication
    #artifactFeed: # string. My feed name (select below). 
    #pythonUploadServiceConnection: # string. Feed from external organizations.
# 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 feeds 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:
  # Feeds and Authentication
    #artifactFeed: # string. My feed (select below). 
    #pythonUploadServiceConnection: # string. Feed from external organizations.

Inputs

artifactFeed - My feed name (select below)
string.

Specifies the Azure artifact's feed name to authenticate with twine. The authenticating feed must be present within the organization. For project-scoped feeds, use the syntax projectName/feedNameSelect.


artifactFeed - My feed (select below)
string.

Specifies the Azure artifact's feed name to authenticate with twine. The authenticating feed must be present within the organization. For project-scoped feeds, use the syntax projectName/feedNameSelect.


pythonUploadServiceConnection - Feed from external organizations
string.

A twine service connection name from an external organization to authenticate with twine. The credentials stored in the endpoint must have package upload permissions.


Task control options

All tasks have control options in addition to their task inputs. For more information, see Control options and common task properties.

Output variables

None.

Remarks

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.

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 invocations of this task will not stack credentials. Every task run 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.

My Pipeline needs to access a feed in a different project

If the pipeline is running in a different project than the project hosting the feed, you must set up the other project to grant read/write access to the build service. See Package permissions in Azure Pipelines for more details.

Examples

The following examples demonstrate how to publish python distribution to Azure Artifacts feed and the official python registry.

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 that 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' in the project 'myTestProject'. Project is needed because the feed is project scoped.
    artifactFeed: myTestProject/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

The artifactFeed input will contain the project and the feed name if the feed is project scoped. If the feed is organization scoped, only the feed name must be provided. Learn more.

Publish Python distribution to the official Python registry

In this example, we are setting up authentication for publishing to the official Python registry. Create a twine service connection entry for pypi. The authenticate task uses that service connection to create a .pypirc file that 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

Requirements

Requirement Description
Pipeline types YAML, Classic build, Classic release
Runs on Agent, DeploymentGroup
Demands None
Capabilities This task does not satisfy any demands for subsequent tasks in the job.
Command restrictions Any
Settable variables Any
Agent version 2.144.0 or greater
Task category Package
Requirement Description
Pipeline types YAML, Classic build, Classic release
Runs on Agent, DeploymentGroup
Demands None
Capabilities This task does not satisfy any demands for subsequent tasks in the job.
Command restrictions Any
Settable variables Any
Agent version 2.120.0 or greater
Task category Package