通过


TwineAuthenticate@1 - Python Twine 上传认证 v1 任务

使用这个任务来认证使用 Tine 上传的 Python 发行版。 将 -r FeedName/EndpointName --config-file $(PYPIRC_PATH) 添加到孪生上传命令。 对于此组织中存在的源,请使用源名称作为存储库(-r)。 否则,请使用服务连接中定义的终结点名称。

语法

# 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
    #azureDevOpsServiceConnection: # string. Alias: workloadIdentityServiceConnection. 'Azure DevOps' Service Connection. 
    #feedUrl: # string. Azure Artifacts Feed url. 
    #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 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.

输入

azureDevOpsServiceConnection - 'Azure DevOps' 服务连接
输入别名workloadIdentityServiceConnection. string

如果设置了, feedUrl 则必须。 其他所有输入都被忽略。


feedUrl - Azure Artifacts 订阅url.
string

如果设置了, workloadIdentityServiceConnection 则必须。 其他所有输入都被忽略。 与 不兼容 pythonUploadServiceConnections。 订阅源的网址应为 pypi 上传注册表格式: https://pkgs.dev.azure.com/{ORG_NAME}/{PROJECT}/_packaging/{FEED_NAME}/pypi/upload/


artifactFeed - “我的源名称”
string

指定 Azure 文件的源名,用 Twinee 认证。 身份验证源必须存在于组织中。 对于项目范围的源,请使用语法 projectName/feedNameSelect


artifactFeed - 我的源(选择下方)
string

指定 Azure 文件的源名,用 Twinee 认证。 身份验证源必须存在于组织中。 对于项目范围的源,请使用语法 projectName/feedNameSelect


从外部组织pythonUploadServiceConnection -
string

孪生服务连接 外部组织的名称进行身份验证。 终结点中存储的凭据必须具有包上传权限。


任务控制选项

除任务输入之外,所有任务都具有控制选项。 有关详细信息,请参阅 控件选项和常见任务属性

输出变量

没有。

注解

为生成范围的 twine 环境变量提供 PYPIRC_PATH 凭据。 这允许你将Python包发布到带有 twine 的构建的订阅源。

何时应在管道中运行此任务?

该任务必须在使用 Twine 上传 Python 发行版到认证包源(如 Azure Artifacts)之前运行。 没有其他订购要求。 此任务的多个调用不会堆叠凭据。 每个任务运行都将清除以前存储的任何凭据。

我的代理位于 Web 代理后面。 TwineAuthenticate 是否会设置孪生体以使用我的代理?

不是。 虽然此任务本身将在 Web 代理后面工作,但代理已配置为使用,但它不会将孪生体配置为使用代理。

我的管道需要访问其他项目中的源

如果管道在与托管源的项目不同的项目中运行,则必须设置其他项目以授予对生成服务的读/写访问权限。 详情请参见 Azure Pipelines 中的 Package 权限。

例子

以下示例展示了如何将 Python 分发发布到 Azure Artifacts 订阅源和官方 Python 注册表。

Publish Python distribution to Azure Artifacts feed

在这个例子中,我们设置了发布的认证到私有的 Azure Artifacts Feed。 身份验证任务创建一个 .pypirc 文件,其中包含将分发版发布到源所需的身份验证凭据。

# 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:
    artifactFeed: projectName/feedName    # For project scoped feeds use: projectName/FeedName, or just feedName for organization scoped feeds
  
- script: |
     python -m twine upload -r feedName --config-file $(PYPIRC_PATH) dist/*.whl # Use -r to pass the repository name (defined in the .pypirc file), and --config-file to point to the .pypirc path set by the TwineAuthenticate task
  displayName: Upload package with Twine

如果源的范围限定,则 artifactFeed 输入将包含项目和源名称。 如果源是组织范围的,则必须仅提供源名称。 了解详细信息

将 Python 发行版发布到官方 Python 注册表

在这个例子中,我们正在设置发布到官方 Python 注册表的认证。 为 pypi创建 孪生服务连接 条目。 身份验证任务使用该服务连接创建一个 .pypirc 文件,其中包含发布分发所需的身份验证凭据。

# 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:
    pythonUploadServiceConnection: pypitest # Name of the Python package upload service connection
  
- script: |
     python -m twine upload -r "pypitest" --config-file $(PYPIRC_PATH) dist/*.whl # Use -r to pass the repository name, and --config-file to point to the .pypirc path set by the TwineAuthenticate task
  displayName: Upload package with Twine

要求

要求 说明
管道类型 YAML,经典版本,经典版本
运行时间 代理,DeploymentGroup
需求 没有
功能 此任务不满足作业中后续任务的任何要求。
命令限制 任何
Settable 变量 任何
代理版本 2.144.0 或更高版本
任务类别 封装件
要求 说明
管道类型 YAML,经典版本,经典版本
运行时间 代理,DeploymentGroup
需求 没有
功能 此任务不满足作业中后续任务的任何要求。
命令限制 任何
Settable 变量 任何
代理版本 2.120.0 或更高版本
任务类别 封装件