你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

az image builder

管理和生成映像生成器模板。

命令

名称 说明 类型 状态
az image builder cancel

根据映像模板取消长时间运行的映像生成。

核心 GA
az image builder create

创建映像生成器模板。

核心 GA
az image builder customizer

管理映像生成器模板定制器。

核心 GA
az image builder customizer add

将映像生成器定制器添加到映像生成器模板。

核心 GA
az image builder customizer clear

从映像生成器模板中删除所有映像生成器自定义工具。

核心 GA
az image builder customizer remove

从映像生成器模板中删除映像生成器定制器。

核心 GA
az image builder delete

删除映像生成器模板。

核心 GA
az image builder error-handler

管理映像生成器模板错误处理程序。

核心 GA
az image builder error-handler add

将错误处理程序添加到现有映像生成器模板。

核心 GA
az image builder error-handler remove

从现有映像生成器模板中删除错误处理程序。

核心 GA
az image builder error-handler show

显示现有映像生成器模板的错误处理程序。

核心 GA
az image builder identity

管理映像生成器模板的标识。

核心 GA
az image builder identity assign

将托管标识添加到现有映像生成器模板。 目前,仅支持一个用户标识。

核心 GA
az image builder identity remove

从现有映像生成器模板中删除托管标识。

核心 GA
az image builder identity show

显示映像生成器模板的托管标识。

核心 GA
az image builder list

列出映像生成器模板。

核心 GA
az image builder optimizer

管理映像生成器模板优化器。

核心 GA
az image builder optimizer add

将优化器添加到现有映像生成器模板。

核心 GA
az image builder optimizer remove

从现有映像生成器模板中删除优化器。

核心 GA
az image builder optimizer show

显示现有映像生成器模板的优化器。

核心 GA
az image builder optimizer update

从现有映像生成器模板更新优化器。

核心 GA
az image builder output

管理映像生成器模板输出分发服务器。

核心 GA
az image builder output add

将映像生成器输出分发服务器添加到映像生成器模板。

核心 GA
az image builder output clear

从映像生成器模板中删除所有映像生成器输出分发服务器。

核心 GA
az image builder output remove

从映像生成器模板中删除映像生成器输出分发服务器。

核心 GA
az image builder output versioning

管理映像生成器模板输出版本器。

核心 GA
az image builder output versioning remove

删除指定输出上的所有版本控制选项。

核心 GA
az image builder output versioning set

设置映像生成器模板的映像生成器输出版本器。

核心 GA
az image builder output versioning show

显示指定输出上的版本控制选项。

核心 GA
az image builder run

生成映像生成器模板。

核心 GA
az image builder show

显示映像生成器模板。

核心 GA
az image builder show-runs

显示映像生成器模板的运行输出。

核心 GA
az image builder trigger

管理映像生成器模板触发器。

核心 GA
az image builder trigger create

为指定的虚拟机映像模板创建触发器。

核心 GA
az image builder trigger delete

删除指定虚拟机映像模板的触发器。

核心 GA
az image builder trigger list

列出指定图像模板资源的所有触发器。

核心 GA
az image builder trigger show

获取指定映像模板资源的指定触发器。

核心 GA
az image builder trigger wait

将 CLI 置于等待状态,直到满足条件。

核心 GA
az image builder update

更新映像生成器模板。

核心 GA
az image builder validator

管理映像生成器模板验证。

核心 GA
az image builder validator add

向现有映像生成器模板添加验证。

核心 GA
az image builder validator remove

从现有映像生成器模板中删除验证。

核心 GA
az image builder validator show

显示现有映像生成器模板的验证。

核心 GA
az image builder wait

将 CLI 置于等待状态,直到满足模板的条件。

核心 GA

az image builder cancel

根据映像模板取消长时间运行的映像生成。

az image builder cancel [--ids]
                        [--name]
                        [--resource-group]
                        [--subscription]

示例

取消映像生成。

az image builder cancel -n mytemplate -g my-group

可选参数

--ids

一个或多个资源 ID(以空格分隔)。 它应该是包含“资源 ID”参数的所有信息的完整资源 ID。 应提供 --id 或其他“资源 ID”参数。

--name -n

映像模板的名称。

--resource-group -g

资源组的名称。 可以使用 az configure --defaults group=<name> 配置默认组。

--subscription

订阅的名称或 ID。 可以使用 az account set -s NAME_OR_ID 配置默认订阅。

全局参数
--debug

提高日志记录详细程度以显示所有调试日志。

--help -h

显示此帮助消息并退出。

--only-show-errors

只显示错误,取消显示警告。

--output -o

输出格式。

接受的值: json, jsonc, none, table, tsv, yaml, yamlc
默认值: json
--query

JMESPath 查询字符串。 有关更多信息和示例,请参阅 http://jmespath.org/

--subscription

订阅的名称或 ID。 可以使用 az account set -s NAME_OR_ID 配置默认订阅。

--verbose

提高日志记录详细程度。 使用 --debug 获取完整的调试日志。

az image builder create

创建映像生成器模板。

az image builder create --name
                        --resource-group
                        [--build-timeout]
                        [--build-vm-identities]
                        [--checksum]
                        [--defer]
                        [--identity]
                        [--image-source]
                        [--image-template]
                        [--location]
                        [--managed-image-destinations]
                        [--no-wait]
                        [--os-disk-size]
                        [--proxy-vm-size]
                        [--scripts]
                        [--shared-image-destinations]
                        [--staging-resource-group]
                        [--subnet]
                        [--tags]
                        [--validator]
                        [--vm-size]
                        [--vnet]

示例

从 Ubuntu2204 映像创建映像生成器模板。 将其分发为托管映像和共享映像库映像版本。 将过渡资源组 ID 指定为将用于生成映像的映像模板。

scripts="https://my-script-url.net/customize_script.sh"
imagesource="Canonical:0001-com-ubuntu-server-jammy:22_04-lts-gen2:latest"

az image builder create --image-source $imagesource -n myTemplate -g myGroup \
    --scripts $scripts --managed-image-destinations image_1=westus \
    --shared-image-destinations my_shared_gallery/linux_image_def=westus,brazilsouth \
    --identity myIdentity --staging-resource-group myStagingResourceGroup

使用映像模板文件创建映像生成器模板。

az image builder create -g my-group -n myTemplate --image-template filename

[高级]使用 CLI 的对象缓存通过 --defer 创建包含多个定制器和分发服务器的图像模板。 支持以下功能:定制器和输出名称、powershell 退出代码、内联脚本、windows 重启、文件定制器、项目标记和 vhd 输出分发服务器。

script="https://my-script-url.com/customize_script.ps1"
imagesource="MicrosoftWindowsServer:WindowsServer:2019-Datacenter:2019.0.20190214"

# create and update template object in local cli cache. Defers put request to ARM
# Cache object ttl set via az configure.
az image builder create --image-source $imagesource -n myTemplate \
    -g myGroup --scripts $script --identity myIdentity --defer

# add customizers
az image builder customizer add -n myTemplate -g myGroup  \
    --customizer-name myPwshScript --exit-codes 0 1 --inline-script \
    "mkdir c:\buildActions" "echo Azure-Image-Builder-Was-Here \
     > c:\buildActions\Output.txt" --type powershell --defer

az image builder customizer add -n myTemplate -g myGroup \
    --customizer-name myFileCustomizer --type file \
    --file-source "https://my-file-source.net/file.txt"  \
    --dest-path "c:\buildArtifacts\file.txt" --defer

# add distributors
az image builder output add -n myTemplate -g myGroup --is-vhd \
    --output-name myWinImageVhd --artifact-tags "is_vhd=True" --defer

az image builder output add -n myTemplate -g myGroup \
    --output-name myWinImageManaged --managed-image winImage \
    --managed-image-location eastus \
    --artifact-tags "is_vhd=False" --defer

# Stop deferring put request to ARM. Create the template from the object cache.
# Cache object will be deleted.
az image builder update -n myTemplate -g myGroup

必需参数

--name -n

映像模板的名称。

--resource-group -g

资源组的名称。 可以使用 az configure --defaults group=<name> 配置默认组。

可选参数

--build-timeout

生成映像模板时等待的最大持续时间(以分钟为单位)。 默认值为 60。

--build-vm-identities

用于在其中部署生成虚拟机的虚拟网络的可选配置。 如果不需要使用任何特定虚拟网络,则可将其省略。

--checksum

Red Hat ISO 映像的 SHA256 检查和。

--defer

暂时将对象存储在本地缓存中,而不是发送到 Azure。 使用 az cache 命令查看/清除。

--identity

用户分配的标识(名称或 ID、分隔空格)图像模板的列表。

--image-source -i

要自定义的基本映像。 必须是有效的平台映像 URN、平台映像别名、Red Hat ISO 映像 URI、托管映像名称/ID 或共享映像版本 ID。

值来自: az vm image list, az vm image show
--image-template

图像模板文件的本地路径或 URL。 使用 --image-template 时,除 -g 和 -n 之外,将忽略所有其他参数。 请参考: https://docs.microsoft.com/azure/virtual-machines/linux/image-builder-json

--location -l

Location。 az account list-locations 中的值。 可以使用 az configure --defaults location=<location> 配置默认位置。

--managed-image-destinations

托管映像输出分发服务器信息。 键值对的空间分隔列表。 例如“image_1=westus2 image_2=westus”。 每个密钥都是要创建的托管映像的名称或资源 ID。 每个值都是图像的位置。

--no-wait

不等待长时间运行的操作完成。

默认值: False
--os-disk-size

OS 磁盘的大小(以 GB 为单位)。 省略或指定 0 以使用 Azure 的默认 OS 磁盘大小。

--proxy-vm-size

用于生成、自定义和捕获映像的虚拟机的大小(第 1 代映像Standard_D1_v2,第 2 代映像Standard_D2ds_v4)。

--scripts

用于自定义映像的 shell 或 powershell 脚本的空间分隔列表。 每个脚本必须是可公开访问的 URL。 从文件扩展名(“.sh”or'.ps1')或源类型推断脚本的类型。 更多定制器选项和灵活性,请参阅:“az image template customizer add”。

--shared-image-destinations

共享映像库 (sig) 输出分发服务器信息。 键值对的空间分隔列表。 例如“my_gallery_1/image_def_1=eastus,westus my_gallery_2/image_def_2=uksouth,canadaeast,francesouth”。每个键都是由“/”分隔的 sig 映像定义 ID 或 sig 库名称和 sig 映像定义。 每个值都是以逗号分隔的副本 (replica)位置列表。

--staging-resource-group

与用于生成映像的映像模板相同的订阅中的暂存资源组 ID。

--subnet

要部署生成虚拟机的子网的名称或 ID。

--tags

空格分隔标记:key[=value] [key[=value] ...]。使用“”清除现有标记。

--validator

要在映像上使用的验证类型。 例如,“Shell”可以是 shell 验证。

--vm-size

用于生成、自定义和捕获映像的虚拟机的大小。 省略或指定空字符串以使用默认值(Standard_D1_v2)。

--vnet

要部署生成虚拟机的 VNET 的名称。 仅当子网是名称时,才应指定它。

全局参数
--debug

提高日志记录详细程度以显示所有调试日志。

--help -h

显示此帮助消息并退出。

--only-show-errors

只显示错误,取消显示警告。

--output -o

输出格式。

接受的值: json, jsonc, none, table, tsv, yaml, yamlc
默认值: json
--query

JMESPath 查询字符串。 有关更多信息和示例,请参阅 http://jmespath.org/

--subscription

订阅的名称或 ID。 可以使用 az account set -s NAME_OR_ID 配置默认订阅。

--verbose

提高日志记录详细程度。 使用 --debug 获取完整的调试日志。

az image builder delete

删除映像生成器模板。

az image builder delete [--ids]
                        [--name]
                        [--resource-group]
                        [--subscription]

示例

删除映像生成器模板。 (自动生成)

az image builder delete --name MyImageTemplate --resource-group MyResourceGroup

可选参数

--ids

一个或多个资源 ID(以空格分隔)。 它应该是包含“资源 ID”参数的所有信息的完整资源 ID。 应提供 --id 或其他“资源 ID”参数。

--name -n

映像模板的名称。

--resource-group -g

资源组的名称。 可以使用 az configure --defaults group=<name> 配置默认组。

--subscription

订阅的名称或 ID。 可以使用 az account set -s NAME_OR_ID 配置默认订阅。

全局参数
--debug

提高日志记录详细程度以显示所有调试日志。

--help -h

显示此帮助消息并退出。

--only-show-errors

只显示错误,取消显示警告。

--output -o

输出格式。

接受的值: json, jsonc, none, table, tsv, yaml, yamlc
默认值: json
--query

JMESPath 查询字符串。 有关更多信息和示例,请参阅 http://jmespath.org/

--subscription

订阅的名称或 ID。 可以使用 az account set -s NAME_OR_ID 配置默认订阅。

--verbose

提高日志记录详细程度。 使用 --debug 获取完整的调试日志。

az image builder list

列出映像生成器模板。

az image builder list [--resource-group]

可选参数

--resource-group -g

资源组的名称。 可以使用 az configure --defaults group=<name> 配置默认组。

全局参数
--debug

提高日志记录详细程度以显示所有调试日志。

--help -h

显示此帮助消息并退出。

--only-show-errors

只显示错误,取消显示警告。

--output -o

输出格式。

接受的值: json, jsonc, none, table, tsv, yaml, yamlc
默认值: json
--query

JMESPath 查询字符串。 有关更多信息和示例,请参阅 http://jmespath.org/

--subscription

订阅的名称或 ID。 可以使用 az account set -s NAME_OR_ID 配置默认订阅。

--verbose

提高日志记录详细程度。 使用 --debug 获取完整的调试日志。

az image builder run

生成映像生成器模板。

az image builder run [--ids]
                     [--name]
                     [--no-wait]
                     [--resource-group]
                     [--subscription]

示例

启动模板生成运行,然后等待它完成。

az image builder run -n mytemplate -g my-group --no-wait

az image builder wait -n mytemplate -g aibmdi \
    --custom "lastRunStatus.runState!='Running'"

az image builder show -n mytemplate -g my-group

可选参数

--ids

一个或多个资源 ID(以空格分隔)。 它应该是包含“资源 ID”参数的所有信息的完整资源 ID。 应提供 --id 或其他“资源 ID”参数。

--name -n

映像模板的名称。

--no-wait

不等待长时间运行的操作完成。

默认值: False
--resource-group -g

资源组的名称。 可以使用 az configure --defaults group=<name> 配置默认组。

--subscription

订阅的名称或 ID。 可以使用 az account set -s NAME_OR_ID 配置默认订阅。

全局参数
--debug

提高日志记录详细程度以显示所有调试日志。

--help -h

显示此帮助消息并退出。

--only-show-errors

只显示错误,取消显示警告。

--output -o

输出格式。

接受的值: json, jsonc, none, table, tsv, yaml, yamlc
默认值: json
--query

JMESPath 查询字符串。 有关更多信息和示例,请参阅 http://jmespath.org/

--subscription

订阅的名称或 ID。 可以使用 az account set -s NAME_OR_ID 配置默认订阅。

--verbose

提高日志记录详细程度。 使用 --debug 获取完整的调试日志。

az image builder show

显示映像生成器模板。

az image builder show [--ids]
                      [--name]
                      [--resource-group]
                      [--subscription]

示例

显示映像生成器模板(自动生成)

az image builder show --name mytemplate  --resource-group my-group

可选参数

--ids

一个或多个资源 ID(以空格分隔)。 它应该是包含“资源 ID”参数的所有信息的完整资源 ID。 应提供 --id 或其他“资源 ID”参数。

--name -n

映像模板的名称。

--resource-group -g

资源组的名称。 可以使用 az configure --defaults group=<name> 配置默认组。

--subscription

订阅的名称或 ID。 可以使用 az account set -s NAME_OR_ID 配置默认订阅。

全局参数
--debug

提高日志记录详细程度以显示所有调试日志。

--help -h

显示此帮助消息并退出。

--only-show-errors

只显示错误,取消显示警告。

--output -o

输出格式。

接受的值: json, jsonc, none, table, tsv, yaml, yamlc
默认值: json
--query

JMESPath 查询字符串。 有关更多信息和示例,请参阅 http://jmespath.org/

--subscription

订阅的名称或 ID。 可以使用 az account set -s NAME_OR_ID 配置默认订阅。

--verbose

提高日志记录详细程度。 使用 --debug 获取完整的调试日志。

az image builder show-runs

显示映像生成器模板的运行输出。

az image builder show-runs [--ids]
                           [--name]
                           [--output-name]
                           [--resource-group]
                           [--subscription]

示例

运行模板生成运行,然后查看其运行输出。

az image builder run -n mytemplate -g my-group --no-wait

az image builder wait -n mytemplate -g aibmdi \
    --custom "lastRunStatus.runState!='Running'"

az image builder show-runs -n mytemplate -g my-group

可选参数

--ids

一个或多个资源 ID(以空格分隔)。 它应该是包含“资源 ID”参数的所有信息的完整资源 ID。 应提供 --id 或其他“资源 ID”参数。

--name -n

映像模板的名称。

--output-name

映像生成器运行输出的名称。

--resource-group -g

资源组的名称。 可以使用 az configure --defaults group=<name> 配置默认组。

--subscription

订阅的名称或 ID。 可以使用 az account set -s NAME_OR_ID 配置默认订阅。

全局参数
--debug

提高日志记录详细程度以显示所有调试日志。

--help -h

显示此帮助消息并退出。

--only-show-errors

只显示错误,取消显示警告。

--output -o

输出格式。

接受的值: json, jsonc, none, table, tsv, yaml, yamlc
默认值: json
--query

JMESPath 查询字符串。 有关更多信息和示例,请参阅 http://jmespath.org/

--subscription

订阅的名称或 ID。 可以使用 az account set -s NAME_OR_ID 配置默认订阅。

--verbose

提高日志记录详细程度。 使用 --debug 获取完整的调试日志。

az image builder update

更新映像生成器模板。

当前不支持更新映像生成器模板。 此命令可与 --defer 结合使用来更新 CLI 缓存中的映像模板对象。 如果不延迟,它将从缓存中检索指定的映像模板,并将请求发送到 Azure 以创建映像模板。

az image builder update [--add]
                        [--defer]
                        [--force-string]
                        [--ids]
                        [--name]
                        [--remove]
                        [--resource-group]
                        [--set]
                        [--subscription]

示例

从 cli 缓存中的模板对象创建模板资源。 有关详细信息,请参阅“az image builder create/ output add / customizer add --help”和“az cache -h”

# create and write template object to local cli cache
az image builder create --image-source {image_source} -n mytemplate -g my-group \
    --scripts {script} --managed-image-destinations image_1=westus --identity myidentity --defer

# add customizers and outputs to local cache template object via az image template output / customizer add
# one can also update cache object properties through generic update options, such as: --set
az image builder output add -n mytemplate -g my-group --output-name my-win-image-managed \
    --artifact-tags "is_vhd=False"  --managed-image winImage --managed-image-location eastus --defer

# send template create request to azure to create template resource
az image builder update -n mytemplate -g my-group

可选参数

--add

通过指定路径和键值对将对象添加到对象列表。 示例:--add property.listProperty <key=value, string or JSON string>

默认值: []
--defer

暂时将对象存储在本地缓存中,而不是发送到 Azure。 使用 az cache 命令查看/清除。

--force-string

使用“set”或“add”时,保留字符串文本,而不是尝试转换为 JSON。

默认值: False
--ids

一个或多个资源 ID(以空格分隔)。 它应该是包含“资源 ID”参数的所有信息的完整资源 ID。 应提供 --id 或其他“资源 ID”参数。

--name -n

映像模板的名称。

--remove

从列表中删除属性或元素。 示例: --remove property.list <indexToRemove> OR --remove propertyToRemove.

默认值: []
--resource-group -g

资源组的名称。 可以使用 az configure --defaults group=<name> 配置默认组。

--set

通过指定要设置的属性路径和值来更新对象。 示例:--set property1.property2=<value>

默认值: []
--subscription

订阅的名称或 ID。 可以使用 az account set -s NAME_OR_ID 配置默认订阅。

全局参数
--debug

提高日志记录详细程度以显示所有调试日志。

--help -h

显示此帮助消息并退出。

--only-show-errors

只显示错误,取消显示警告。

--output -o

输出格式。

接受的值: json, jsonc, none, table, tsv, yaml, yamlc
默认值: json
--query

JMESPath 查询字符串。 有关更多信息和示例,请参阅 http://jmespath.org/

--subscription

订阅的名称或 ID。 可以使用 az account set -s NAME_OR_ID 配置默认订阅。

--verbose

提高日志记录详细程度。 使用 --debug 获取完整的调试日志。

az image builder wait

将 CLI 置于等待状态,直到满足模板的条件。

az image builder wait [--created]
                      [--custom]
                      [--deleted]
                      [--exists]
                      [--ids]
                      [--interval]
                      [--name]
                      [--resource-group]
                      [--subscription]
                      [--timeout]
                      [--updated]

示例

启动模板生成运行,然后等待它完成。

az image builder run -n mytemplate -g my-group --no-wait

az image builder wait -n mytemplate -g aibmdi \
    --custom "lastRunStatus.runState!='Running'"

az image builder show -n mytemplate -g my-group

可选参数

--created

等待在“Succeeded”中使用“provisioningState”创建。

默认值: False
--custom

等待条件满足自定义 JMESPath 查询。 例如 provisioningState!='InProgress', instanceView.statuses[?code=='PowerState/running']。

--deleted

等到删除为止。

默认值: False
--exists

等待资源存在。

默认值: False
--ids

一个或多个资源 ID(以空格分隔)。 它应该是包含“资源 ID”参数的所有信息的完整资源 ID。 应提供 --id 或其他“资源 ID”参数。

--interval

轮询间隔(以秒为单位)。

默认值: 30
--name -n

映像模板的名称。

--resource-group -g

资源组的名称。 可以使用 az configure --defaults group=<name> 配置默认组。

--subscription

订阅的名称或 ID。 可以使用 az account set -s NAME_OR_ID 配置默认订阅。

--timeout

最大等待(以秒为单位)。

默认值: 3600
--updated

等到 provisioningState 更新为“Succeeded”。

默认值: False
全局参数
--debug

提高日志记录详细程度以显示所有调试日志。

--help -h

显示此帮助消息并退出。

--only-show-errors

只显示错误,取消显示警告。

--output -o

输出格式。

接受的值: json, jsonc, none, table, tsv, yaml, yamlc
默认值: json
--query

JMESPath 查询字符串。 有关更多信息和示例,请参阅 http://jmespath.org/

--subscription

订阅的名称或 ID。 可以使用 az account set -s NAME_OR_ID 配置默认订阅。

--verbose

提高日志记录详细程度。 使用 --debug 获取完整的调试日志。