You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Azure PowerShell任务更新Azure云服务扩展支持遇API版本错误

问题解决:Update-AzCloudService API版本不匹配错误

核心原因

你遇到的指定的api-version 2021-03-01不符合设置SlotType属性所需的最低api-version 2022-04-04错误,本质是Azure PowerShell 3.1.0版本过低:即使安装了最新的Az.CloudService 1.1.0模块,底层调用的Azure REST API版本仍停留在2021-03-01,无法支持SlotType属性所需的2022-04-04及以上API版本。

Az模块的API版本绑定逻辑为:基础Az模块(而非单独的Az.CloudService模块)决定REST API的调用版本,旧版本基础Az模块无法触发新版本API的调用。

解决方案

1. 升级Azure PowerShell任务的首选版本

在Azure DevOps发布管道的Azure PowerShell任务配置中,将Azure PowerShell版本选项 - 首选Azure PowerShell版本从3.1.0改为7.x版本(如7.2或更高)。

这是最直接的修复方式,新版本Az模块默认调用符合要求的API版本,可适配Az.CloudService 1.1.0的功能需求。

2. 调整代码的参数传递方式

避免手动构造哈希表作为-InputObject参数,改为通过Get-AzCloudService获取云服务对象,确保对象携带正确的API版本上下文:

# 获取目标云服务的完整对象(自动携带正确API版本信息)
$cloudServiceObj = Get-AzCloudService -ResourceGroupName $resourceGroupName -CloudServiceName $cloudServiceName

# 准备更新参数
$updateParams = @{
    ConfigurationUrl = $configSas 
    PackageUrl = $packageSas
    OSProfile = $osProfile
}

# 执行更新操作
Write-Host "Starting Azure CSES Update"
Update-AzCloudService -InputObject $cloudServiceObj @updateParams
Write-Host "Completed Azure CSES Update"

3. 验证Azure DevOps任务版本(可选)

若Azure DevOps Server 2020 Update 1.1支持,将Azure PowerShell任务从版本5升级到最新可用版本,确保任务能正确加载新版本Az模块环境。

验证步骤

修改配置后重新运行发布管道,检查是否仍出现API版本不匹配错误。可在PowerShell任务中添加以下命令,确认当前使用的Az模块版本:

Get-Module -ListAvailable Az
Get-Module Az.CloudService

内容的提问来源于stack exchange,提问作者4JTB

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 03:05:28