使用 Azure Pipelines 发布 Python 包
Azure DevOps Services
使用Azure Pipelines,可以将 Python 包发布到Azure Artifacts源、公共注册表或管道项目。
本文将向你介绍如何:
- 安装
Twine - 使用Azure Artifacts源进行身份验证
- 将 Python 包发布到Azure Artifacts源
安装孪生体
使用 Azure Artifacts 进行身份验证
若要用于twine发布 Python 包,必须先设置Azure Artifacts源的身份验证。 TwineAuthenticate 任务将凭据存储在环境变量中PYPIRC_PATH。 twine 将引用此变量以从管道发布包。
- 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:源的名称。
- pythonUploadServiceConnection:用于通过孪生进行身份验证 的服务连接 。
提示
存储在环境变量中的 PYPIRC_PATH 凭据取代了这些文件 .ini 和 .conf 文件中的凭据。
如果在管道的不同阶段添加多个 TwineAuthenticate 任务,则每个额外的任务执行将扩展 (不会替代 现有 PYPIRC_PATH 环境变量) 。
将 Python 包发布到Azure Artifacts源
- 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
。
