4

我正在尝试设置 Azure Devops 以使用 Poetry 发布到 PyPI 提要。

我知道 Twine 身份验证和将凭据存储到 Azure Key Vault。但是有没有更直接的方法呢?像这样的东西:

- script: |
    source .venv/bin/activate
    poetry build
  displayName: Build wheel
- script: |
    source .venv/bin/activate
    poetry publish -u USER -p PASS
  displayName: Publish wheel
4

3 回答 3

6

是的。在 Azure DevOps Web 界面中:

  1. 创建一个新的 PyPI 提要(工件 > 新提要 > 创建)。
  2. 创建 PyPI 凭据(连接到 feed > Python > 生成 Python 凭据)。
  3. 创建使用 PyPI 凭据命名和赋值的秘密管道变量(管道 > 编辑 > 变量 > 新变量 > 将此值保密 > 确定)。usernamepassword
  4. 使用以下命令更新azure-pipelines.ymlCI 文件的内容:
trigger:
- master

pool:
  vmImage: ubuntu-latest

steps:
- task: UsePythonVersion@0
  inputs:
    versionSpec: 3.7
  displayName: Install Python
- script: |
    python -m pip install -U pip
    pip install poetry
    poetry install
  displayName: Install software
- script: |
    poetry run python -m unittest discover tests/ -v
  displayName: Test software
- script: |
    poetry build
  displayName: Package software
- script: |
    poetry config repositories.azure https://pkgs.dev.azure.com/{your organization}/_packaging/{your feed}/pypi/upload
    poetry config http-basic.azure $(username) $(password)
    poetry publish -r azure
    exit 0
  displayName: Publish software
于 2019-09-16T13:11:16.467 回答
1

您可能想要使用 $(System.AccessToken) 变量:

- task: Bash@3
    inputs:
      targetType: 'inline'
      script: |
        poetry config repositories.myazurepypi https://myorg.pkgs.visualstudio.com/123415462134546/_packaging/lcp-tools/pypi/upload/
        poetry publish -r myazurepypi -u a -p $(System.AccessToken)
于 2021-05-27T20:35:20.550 回答
0

poetry使用 构建和发布怎么样twine,这样我们就可以利用 Azure 自己的TwineAuthenticate

steps:
  - task: UsePythonVersion@0
    inputs:
      versionSpec: '$(python.version)'
    displayName: 'Use Python $(python.version)'

  - script: |
      python -m pip install --upgrade pip
      pip install poetry
      pip install twine
      poetry install --no-dev
    displayName: 'Install dependencies'

  - script: |
      poetry build
    displayName: 'Build package'

  - task: TwineAuthenticate@1
    inputs:
      artifactFeed: 'repo-name/feed-name'

  - script: |
      twine upload -r repo-name --config-file $(PYPIRC_PATH) dist/*.whl
    displayName: Upload package to Azure Artifact
于 2021-07-13T21:49:04.077 回答