Azure自托管Agent运行Pipeline时EPERM权限错误排查求助
问题描述
我在本地服务器创建了已在Azure上正常运行的自托管Agent,并在azure_pipelines.yml中添加了池信息:
pool: name: TestPool demands: - agent.name -equals Test_Agent_01
运行Pipeline时,以下两个任务触发错误:
第一个任务:
- task: UsePythonVersion@0 inputs: versionSpec: '3.x' addToPath: true architecture: 'x64' displayName: 'Use Python 3.x'
第二个任务:
- task: DownloadPackage@1 inputs: packageType: 'pypi' feed: 'feedid' view: 'viewid' definition: 'defid' version: '0.0.2' downloadPath: '$(Build.SourcesDirectory)'
Pipeline运行时的错误信息如下:
Starting: Use Python 3.x ============================================================================== Task : Use Python version Description : Use the specified version of Python from the tool cache, optionally adding it to the PATH Version : 0.220.0 Author : Microsoft Corporation Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/tool/use-python-version ============================================================================== node:internal/fs/utils:347 throw err; ^ Error: EPERM: operation not permitted, lstat 'path' at Object.realpathSync (node:fs:2538:7) at toRealPath (node:internal/modules/cjs/loader:405:13) at Function.Module._findPath (node:internal/modules/cjs/loader:548:24) at Function.Module._resolveFilename (node:internal/modules/cjs/loader:942:27) at Function.Module._load (node:internal/modules/cjs/loader:804:27) at Module.require (node:internal/modules/cjs/loader:1028:19) at Module._preloadModules (node:internal/modules/cjs/loader:1303:12) at loadPreloadModules (node:internal/bootstrap/pre_execution:583:5) at prepareMainThreadExecution (node:internal/bootstrap/pre_execution:95:3) at node:internal/main/run_main_module:7:1 { errno: -4048, syscall: 'lstat', code: 'EPERM', path: 'path' } ##[error]Exit code 1 returned from process: file name "filename' arguments 'arguments'
请问可能缺失哪些配置或权限?
可能的原因及解决方向
- Agent运行账户权限不足:自托管Agent的运行账户对以下路径没有读写权限:
- Python工具缓存目录(默认是Agent安装目录下的
_work/_tool/Python) $(Build.SourcesDirectory)对应的本地目录
解决:给Agent运行账户添加上述目录的完全控制权限,或者切换到拥有足够权限的账户启动Agent。
- Python工具缓存目录(默认是Agent安装目录下的
- Python工具缓存未初始化或损坏:
UsePythonVersion@0任务会从Agent的工具缓存里找指定版本的Python,如果缓存目录不存在或权限异常,会触发lstat操作失败。
解决:手动在Agent机器上安装对应版本的Python,然后在Pipeline里直接用绝对路径调用;或者手动将Python安装目录软链到工具缓存路径。 - 下载路径权限/占用问题:
DownloadPackage@1任务要把包下载到$(Build.SourcesDirectory),如果这个目录被其他进程锁定,或者Agent账户没有写入权限,会报错。
解决:检查$(Build.SourcesDirectory)的权限,确保Agent账户可读写;避免其他进程占用该目录。 - Agent安装目录权限异常:Agent本身的安装目录或工作目录权限不足,导致node.js进程无法读取必要文件。
解决:检查Agent安装目录和_work目录的权限,给运行账户添加完全控制权限。 - Windows系统权限限制:如果是Windows服务器,可能存在UAC限制或者文件夹被标记为只读/受保护。
解决:临时关闭UAC测试,或者把Agent安装在非系统盘的普通目录,取消文件夹的只读属性。
内容的提问来源于stack exchange,提问作者speed0001
相关产品推荐
相关产品推荐

