TwineAuthenticate@1 - Python 孪生上传身份验证 v1 任务
使用此任务通过孪生对 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
#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.
输入
artifactFeed
-
“我的源名称”
string
。
指定要使用孪生进行身份验证的 Azure 项目的源名称。 身份验证源必须存在于组织中。 对于项目范围的源,请使用语法 projectName/feedNameSelect
。
artifactFeed
-
我的源(选择下方)
string
。
指定要使用孪生进行身份验证的 Azure 项目的源名称。 身份验证源必须存在于组织中。 对于项目范围的源,请使用语法 projectName/feedNameSelect
。
任务控制选项
除任务输入之外,所有任务都具有控制选项。 有关详细信息,请参阅 控件选项和常见任务属性。
输出变量
没有。
注解
为生成范围的 PYPIRC_PATH
环境变量提供 twine
凭据。 这样,便可以使用生成中的 twine
将 Python 包发布到源。
何时应在管道中运行此任务?
必须先运行此任务,然后才能使用孪生将 Python 分发版上传到经过身份验证的包源,例如 Azure Artifacts。 没有其他订购要求。 此任务的多个调用不会堆叠凭据。 每个任务运行都将清除以前存储的任何凭据。
我的代理位于 Web 代理后面。 TwineAuthenticate 是否会设置孪生体以使用我的代理?
不是。 虽然此任务本身将在 Web 代理后面工作,但代理已配置为使用,但它不会将孪生体配置为使用代理。
我的管道需要访问其他项目中的源
如果管道在与托管源的项目不同的项目中运行,则必须设置其他项目以授予对生成服务的读/写访问权限。 有关详细信息,请参阅 Azure Pipelines 中的 包权限。
例子
以下示例演示如何将 Python 分发发布到 Azure Artifacts 源和官方 Python 注册表。
将 Python 分发发布到 Azure Artifacts 源
在此示例中,我们将设置用于发布到专用 Azure Artifacts 源的身份验证。 身份验证任务创建一个 .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:
# 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
如果源的范围限定,则 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:
# 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