我已在本地虚拟机上安装了自托管代理,它连接到 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 设置工具目录的(不完整)详细信息:
上述文档中的谜团是,它们引用的那些“tool_files”是什么?
值得庆幸的是,GitHub 上的 jrm346 通过源代码解决了这个问题;对于 Linux,您需要从源代码编译 Python 并重新配置目标目录:
https://github.com/microsoft/azure-pipelines-tasks/issues/10721
对于 Python 3.8:
在代理工具的目录下创建所需的文件结构:
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/