python - 用于运行 pytest 的 Azure 自托管代理

标签 python azure azure-devops pytest

我已在本地虚拟机上安装了自托管代理,它连接到 azure 时没有任何问题。 我在 azure DevOps 上有一个 python 代码 我已将所有requirements.txt要求手动安装到本地VM的cmd行中,以便安装在其上的自托管代理不必安装它们(以最大限度地减少构建和部署时间)

但是当我在 YAML 文件中有以下代码来运行 pytest 时,管道由于以下错误而失败

这是我的 Yaml 文件

    trigger:
        - master
        variables:
          python.version : 3.8.6

        stages:
        - stage: Build
          jobs: 
          - job: Build
            pool:
              name: 'MaitQA'
            #pool:
            #  vmImage: 'windows-latest'   # windows-latest Or windows-2019 ; vs2017-win2016 # https://learn.microsoft.com/en-us/azure/devops/pipelines/agents/hosted?view=azure-devops&tabs=yaml#software # vs2017-win2016

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

        - script: 'pip install pytest pytest-azurepipelines ; pytest unit_test/'
                

This is The error --------------- Starting: Use Python 3.8.6 ------------------------------ Task : Use Python version Description : Use the specified version of Python from the tool cache, optionally adding it to the PATH Version : 0.151.4 Author : Microsoft Corporation Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/tool/use-python-version ------------------------------------------- [error]Version spec 3.8.6 for architecture x64 did not match any version in Agent.ToolsDirectory. Versions in C:\CodeVersions_tool: If this is a Microsoft-hosted agent, check that this image supports side-by-side versions of Python at https://aka.ms/hosted-agent-software. If this is a self-hosted agent, see how to configure side-by-side Python versions at https://go.microsoft.com/fwlink/?linkid=871498. Finishing: Use Python 3.8.6 ---------------

最佳答案

此错误是指 Python 不在代理工具目录中,因此代理无法使用。

以下是使用 Python 设置工具目录的(不完整)详细信息:

https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/tool/use-python-version?view=azure-devops#how-can-i-configure-a-self-hosted-agent-to-use-this-task

上述文档中的谜团是,它们引用的那些“tool_files”是什么?

值得庆幸的是,GitHub 上的 jrm346 通过源代码解决了这个问题;对于 Linux,您需要从源代码编译 Python 并重新配置目标目录:

https://github.com/microsoft/azure-pipelines-tasks/issues/10721

对于 Python 3.8:

  1. 在代理工具的目录下创建所需的文件结构:

    Python

     └── 3.8.0
         ├── x64
         └── x64.complete
    

然后按照以下说明编译 Python 3.8.6,并添加一点:在第 4 步的“/configure --enable-optimizations”之后运行命令“./configure” --prefix=/home/azure/_work/_tool/Python/3.8.0/x64',将 '/home/azure/_work/_tool' 替换为代理的工具目录位置:

https://linuxize.com/post/how-to-install-python-3-8-on-ubuntu-18-04/

关于python - 用于运行 pytest 的 Azure 自托管代理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64212888/

相关文章:

azure - 创建与 Azure IoT 中心通信所需的 SAS key

azure-devops - 如何在 Yaml 中指定 Azure 管道中 AZ CLI 的版本?

rest - 如何使用 Azure DevOps REST API 创建新的构建管道?

azure - 获取从另一个管道下载的最后一个工件的值

azure - Cosmos DB OFFSET LIMIT(NoSQL 查询)RU 成本

具有公共(public) IP 的应用程序网关后面的 Azure 容器组

python - 生成具有正确缩进的 XML 文件

python - 通过相等的第一个字段组合/分组/合并列表列表,在字符串中加入第二个字段并在其他字段中写入相同的数据

python - Python/Pygame 中用于识别按键的正则表达式

python - 根据一组特定的单词拆分字符串