Azure DevOps自托管代理执行任务失败:Windows环境报错求助
修复方案
检查PowerShell执行策略
以管理员身份打开PowerShell,运行Get-ExecutionPolicy,若结果为Restricted,执行Set-ExecutionPolicy RemoteSigned(按提示确认),允许脚本正常运行。强制代理使用Windows PowerShell 5.1
部分旧任务仅兼容Windows Desktop PowerShell(5.1版本),而非PowerShell Core(7+)。操作方式:- 停止Azure DevOps代理服务
- 打开代理安装目录下的
config.cmd,重新配置代理,在PowerShell版本选项中选择Windows PowerShell - 或直接设置环境变量
VSTS_AGENT_PS_EDITION=Desktop后重启代理服务
确认代理运行账户权限
打开系统服务管理器,找到Azure Pipelines Agent服务,确保其以本地系统账户或拥有管理员权限的Windows账户运行,避免权限受限导致任务执行失败。更新Azure DevOps代理版本
卸载当前代理,下载最新Windows版代理重新安装配置,旧版本代理可能存在兼容性bug。检查任务配置
在Pipeline编辑界面,确保Web Config Transform、Copy Files等任务的PowerShell版本设置为Windows PowerShell 5.1,而非PowerShell Core。
错误提示原文:
##[error]The current operating system is not capable of running this task. That typically means the task was written for Windows only. For example, written for Windows Desktop PowerShell.
##[debug]System.InvalidOperationException: The current operating system is not capable of running this task. That typically means the task was written for Windows only. For example, written for Windows Desktop PowerShell.
内容的提问来源于stack exchange,提问作者Mr W

