如何在Azure Pipelines中收集VS Code扩展测试日志?
VS Code扩展集成测试Azure Pipelines日志路径问题
我正在开发一款VS Code扩展,其集成测试仅在Azure Pipelines运行时失败,需要收集VS Code日志分析原因。本地环境中,Windows系统日志路径为%appdata%\Code\logs,Linux系统为~/.config/Code/logs,但Azure Pipelines中这些路径未生成日志。
我需要编写Azure Pipelines步骤发布日志,示例代码如下:
- publish: ${{ parameters.logsLocation }} artifact: VS Code logs ($(Agent.JobName)) displayName: Publishing VS Code logs condition: succeededOrFailed()
我已尝试以下logsLocation值:
- $(AppData)/Roaming/Code/logs
- /home/vsts/.config/Code/logs
- ~/AppData/Roaming/Code/logs
- ~/.config/Code/logs
请问应从哪个路径发布日志?
正确路径与配置方案
Azure Pipelines代理环境中,VS Code日志路径需根据代理操作系统区分设置,同时注意VS Code的运行身份:
1. Windows代理
Azure Pipelines Windows代理默认使用vsts用户,正确路径为:
$(AppData)\Code\logs
注:$(AppData)本身已指向C:\Users\vsts\AppData\Roaming,无需额外添加Roaming层级。
2. Linux代理
Linux代理默认用户为vsts,正确路径为:
/home/vsts/.config/Code/logs
或使用用户目录变量简化:
$(HOME)/.config/Code/logs
3. 跨平台通用参数化配置
若Pipeline同时运行在Windows和Linux代理上,可通过条件判断动态设置路径:
steps: - ${{ if eq(variables['Agent.OS'], 'Windows_NT') }}: - script: echo "##vso[task.setvariable variable=logsLocation]$(AppData)\Code\logs" displayName: Set Windows logs path - ${{ if eq(variables['Agent.OS'], 'Linux') }}: - script: echo "##vso[task.setvariable variable=logsLocation]$(HOME)/.config/Code/logs" displayName: Set Linux logs path - publish: $(logsLocation) artifact: VS Code logs ($(Agent.JobName)) displayName: Publishing VS Code logs condition: succeededOrFailed()
额外排查步骤
若以上路径仍无日志,可添加步骤验证目录状态:
# Windows - script: dir $(AppData)\Code\logs condition: eq(variables['Agent.OS'], 'Windows_NT') displayName: Check Windows logs directory # Linux - script: ls -la $(HOME)/.config/Code/logs condition: eq(variables['Agent.OS'], 'Linux') displayName: Check Linux logs directory
同时确认集成测试是否正确启动VS Code实例、日志功能未被禁用,以及运行时是否有目录写入权限。
内容的提问来源于stack exchange,提问作者Andrew Arnott
相关产品推荐
相关产品推荐

