Azure DevOps Scale Set Agent缺失pwsh,任务执行失败求助
解决Scale Set Agents中PowerShell@2/AzureCLI@2任务的
pwsh找不到问题 是的,你必须给Ubuntu LTS镜像的Scale Set Agents安装PowerShell(pwsh),原因如下:
- Microsoft-hosted agents是微软预配置的环境,默认包含PowerShell、Azure CLI等DevOps常用工具;
- 自托管的Scale Set Agents使用原生Ubuntu LTS基础镜像,默认仅带系统基础组件,没有预装PowerShell。
用Custom Script Extension安装PowerShell的步骤
- 创建一个bash脚本(比如
install-pwsh.sh),内容如下:
# 更新包列表并安装依赖 sudo apt-get update && sudo apt-get install -y wget apt-transport-https software-properties-common # 导入Microsoft软件源密钥和源 wget -q "https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/packages-microsoft-prod.deb" sudo dpkg -i packages-microsoft-prod.deb rm packages-microsoft-prod.deb # 安装PowerShell sudo apt-get update && sudo apt-get install -y powershell # 验证安装成功 pwsh --version
- 将这个脚本配置到Scale Set的Custom Script Extension中:
- 进入Azure Portal的Scale Set资源页面
- 切换到「扩展」选项卡,添加「Custom Script Extension」
- 上传或指定脚本的存储路径(如Azure存储账户的blob),配置执行权限
- 配置完成后,Scale Set中现有和新创建的VM都会自动执行脚本安装PowerShell,之后流水线任务就能找到
pwsh命令。
关于AzureCLI@2任务的补充说明
如果你的AzureCLI@2任务设置了scriptType: pscore(即用PowerShell运行CLI脚本),就必须依赖pwsh;如果脚本是bash语法,可以临时把scriptType改成bash绕过问题,但如果需要用PowerShell编写CLI脚本,还是得安装pwsh。
内容的提问来源于stack exchange,提问作者Mike
相关产品推荐
相关产品推荐

