AzureVmssDeployment@0 - Azure VM 规模集部署 v0 任务

此任务部署虚拟机规模集映像。

语法

# Azure VM scale set deployment v0
# Deploy a virtual machine scale set image.
- task: AzureVmssDeployment@0
  inputs:
  # Azure Details
    azureSubscription: # string. Alias: ConnectedServiceName. Required. Azure subscription. 
    action: 'Update image' # 'Update image' | 'Configure application startup'. Required. Action. Default: Update image.
    vmssName: # string. Required. Virtual Machine scale set name. 
    vmssOsType: # 'Windows' | 'Linux'. Required. OS type. 
  # Image Details
    #imageUrl: # string. Required when action = Update image || action = UpdateImage. Image URL. 
  # Configure start-up
    #customScriptsDirectory: # string. Optional. Use when action = Configure application startup || action = Update image || action = UpdateImage. Custom script directory. 
    #customScript: # string. Optional. Use when action = Configure application startup || action = Update image || action = UpdateImage. Command. 
    #customScriptArguments: # string. Optional. Use when action = Configure application startup || action = Update image || action = UpdateImage. Arguments. 
    #customScriptsStorageAccount: # string. Optional. Use when action = Configure application startup || action = Update image || action = UpdateImage. Azure storage account where custom scripts will be uploaded. 
  # Advanced
    #skipArchivingCustomScripts: false # boolean. Skip Archiving custom scripts. Default: false.
# Azure VM scale set Deployment v0
# Deploy Virtual Machine scale set image.
- task: AzureVmssDeployment@0
  inputs:
  # Azure Details
    azureSubscription: # string. Alias: ConnectedServiceName. Required. Azure subscription. 
    action: 'Update image' # 'Update image' | 'Configure application startup'. Required. Action. Default: Update image.
    vmssName: # string. Required. Virtual Machine scale set name. 
    vmssOsType: # 'Windows' | 'Linux'. Required. OS type. 
  # Image Details
    #imageUrl: # string. Required when action = Update image || action = UpdateImage. Image URL. 
  # Configure start-up
    #customScriptsDirectory: # string. Optional. Use when action = Configure application startup || action = Update image || action = UpdateImage. Custom script directory. 
    #customScript: # string. Optional. Use when action = Configure application startup || action = Update image || action = UpdateImage. Command. 
    #customScriptArguments: # string. Optional. Use when action = Configure application startup || action = Update image || action = UpdateImage. Arguments. 
    #customScriptsStorageAccount: # string. Optional. Use when action = Configure application startup || action = Update image || action = UpdateImage. Azure storage account where custom scripts will be uploaded. 
  # Advanced
    #skipArchivingCustomScripts: false # boolean. Skip Archiving custom scripts. Default: false.

输入

azureSubscription - Azure 订阅
输入别名: ConnectedServiceNamestring. 必需。

指定规模集的 Azure 资源管理器订阅。


action - 行动
string. 必需。 允许的值: Update image (使用映像) 更新 VM 规模集, Configure application startup (VM 规模集) 运行自定义脚本 VM 扩展。 默认值:Update image

通过所选方法、使用 VHD 映像和/或使用自定义脚本 VM 扩展运行部署/安装脚本来汇报 VM 规模集。

VHD 映像方法 更适合快速缩放和执行回滚。 使用自定义映像创建 VM 规模集时,可以通过 VHD 映像对其进行更新。 如果 VM 规模集是使用 Azure 中可用的平台/库映像创建的,则更新将失败。

自定义脚本 VM 扩展方法 适用于部署后配置、软件安装或任何其他配置/管理任务。 自定义脚本 VM 扩展方法可用于使用自定义映像或平台/库映像创建的 VM 规模集。


vmssName - 虚拟机规模集名称
string. 必需。

指定要更新的 VM 规模设置的名称。 使用 VHD 映像或自定义脚本 VM 扩展。


vmssOsType - OS 类型
string. 必需。 允许的值:WindowsLinux

指定 VM 规模集的操作系统类型。


imageUrl - 图像 URL
string. 当 action = Update image || action = UpdateImage 时,需要此选项。

指定 VHD 映像的 URL。 如果是 Azure 存储 Blob URL,则存储帐户位置与规模集位置相同。


customScriptsDirectory - 自定义脚本目录
string. 可选。 在 时 action = Configure application startup || action = Update image || action = UpdateImage使用 。

可选。 包含自定义脚本的目录的路径 (使用自定义脚本 VM 扩展运行的) 。 扩展方法适用于部署后配置、应用程序/软件安装或任何其他的应用程序配置/管理任务。 例如,脚本可以设置应用程序使用的计算机级环境变量,例如数据库连接字符串。


customScript - 命令
string. 可选。 在 时 action = Configure application startup || action = Update image || action = UpdateImage使用 。

可选。 使用自定义脚本 VM 扩展运行的脚本。 此脚本可以调用目录中的其他脚本,并使用下面传递的参数进行调用。
与此类参数一起,此脚本可用于执行命令。

例如:

  1. Update-DatabaseConnectionStrings.ps1 -clusterType dev -user $(dbUser) -password $(dbUserPwd)更新 Web 应用程序中的连接字符串web.config
  2. install-secrets.sh --key-vault-type prod -key serviceprincipalkey 创建包含服务主体密钥的加密文件。

customScriptArguments - 参数
string. 可选。 在 时 action = Configure application startup || action = Update image || action = UpdateImage使用 。

可选。 将使用传递的参数调用自定义脚本。 可以使用生成/发布变量,这使得使用机密变得容易。


customScriptsStorageAccount - 用于上传自定义脚本的 Azure 存储帐户
string. 可选。 在 时 action = Configure application startup || action = Update image || action = UpdateImage使用 。

可选。 自定义脚本扩展在 VM 规模集中的每个虚拟机上下载并执行提供的脚本。 这些脚本将存储在此处指定的预先存在的 ARM 存储帐户中。


skipArchivingCustomScripts - 跳过存档自定义脚本
boolean. 默认值:false

可选。 默认情况下,此任务会创建包含自定义脚本的目录的压缩存档。 这可以提高上传到 Azure 存储时的性能和可靠性。 如果未选择此项,则不会进行存档,将单独上传所有文件。


任务控制选项

除了任务输入,所有任务都有控制选项。 有关详细信息,请参阅 控制选项和常见任务属性

输出变量

无。

备注

使用此任务部署虚拟机规模集映像。

脚本执行报告为成功,但 VMSS 实例不会更新

规模集有一个升级策略,用于确定如何使用最新的规模集模型使 VM 处于最新状态,如果升级策略设置为手动,则必须手动升级每个 VM。 有关详细信息,请参阅 如何使用最新的规模集模型使 VM 更新。 可以更改更新策略或手动升级每个 VM。 例如,若要将策略升级到 Automatic,请使用以下 Az CLI 命令: az vmss update --set upgradePolicy.mode=Automatic -g <resource group name> -n <vmss name>

错误:“权限被拒绝: 脚本不可执行”

如果尝试运行自定义脚本,但该脚本不可执行,则会出现此问题。

若要解决此问题,请首先确保 customScript 输入在脚本名称 'test.sh' 之前没有 ./ 或任何其他内容:

    customScript: 'test.sh'

接下来,尝试在虚拟机规模集任务之前添加命令行任务:

    - task: CmdLine@2
      inputs:
        script: 'chmod 777 $(System.DefaultWorkingDirectory)/test.sh' 

要求

要求 说明
管道类型 YAML、经典版本、经典版本
运行平台 Agent、DeploymentGroup
需求
功能 此任务不满足作业中后续任务的任何要求。
命令限制 任意
可设置变量 任意
代理版本 2.0.0 或更高版本
任务类别 部署