TwineAuthenticate@1 - Python 對應項上傳驗證 v1 工作

使用此工作,使用對應項驗證 Python 散發套件的上傳。 將 新增 -r FeedName/EndpointName --config-file $(PYPIRC_PATH) 至對應項上傳命令。 對於此組織中存在的摘要,請使用摘要名稱作為存放庫 (-r) 。 否則,請使用服務連線中定義的端點名稱。

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 (select below). 
    #pythonUploadServiceConnection: # string. Feed from external organizations.

輸入

artifactFeed - 我的摘要 (選取下方)
string.

指定要使用對應項進行驗證的 Azure 成品摘要名稱。 驗證摘要必須存在於組織內。 針對專案範圍的摘要,請使用 語法 projectName/feedNameSelect


pythonUploadServiceConnection - 來自外部組織的摘要
string.

來自外部組織的對應 項服務連線 名稱,以使用對應項進行驗證。 儲存在端點中的認證必須具有套件上傳許可權。


工作控制項選項

除了工作輸入之外,所有工作都有控制選項。 如需詳細資訊,請參閱 控制選項和一般工作屬性

輸出變數

無。

備註

PYPIRC_PATH提供 twine 組建範圍的環境變數認證。 這可讓您從組建將 Python 套件發佈至摘要 twine

我管線中的何時應該執行這項工作?

此工作必須先執行,才能使用對應項將 Python 散發套件上傳至已驗證的套件來源,例如 Azure Artifacts。 沒有其他排序需求。 此工作的多個調用不會堆疊認證。 每個工作執行都會清除任何先前儲存的認證。

我的代理程式位於 Web Proxy 後方。 TwineAuthenticate 是否會設定對應項來使用我的 Proxy?

不會。 雖然此工作本身會在 代理程式設定為使用的 Web Proxy後方運作,但不會將對應項設定為使用 Proxy。

我的管線需要存取不同專案中的摘要

如果管線在裝載摘要的專案不同的專案中執行,您必須設定其他專案,以授與建置服務的讀取/寫入權限。 如需詳細資訊 ,請參閱 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

規格需求

需求 說明
管線類型 YAML、傳統組建、傳統版本
在 上執行 Agent、DeploymentGroup
要求
Capabilities 此工作不符合作業中後續工作的任何需求。
命令限制 任意
可設定變數 任意
代理程式版本 2.144.0 或更新版本
工作類別 套件
需求 說明
管線類型 YAML、傳統組建、傳統版本
在 上執行 Agent、DeploymentGroup
要求
Capabilities 此工作不符合作業中後續工作的任何需求。
命令限制 任意
可設定變數 任意
代理程式版本 2.120.0 或更新版本
工作類別 套件