Azure 开发人员 CLI(azd)允许使用一组 azd 命令管理 azd config 配置。 这些配置设置包括有用的默认值,例如 Azure 订阅和位置,以及其他 azd 命令或功能使用的设置。 还可以获取和设置自己的自定义值,并在脚本或自定义功能中使用它们。
在本文中,你将了解:
- 有关 Azure 开发人员 CLI 配置的关键概念
- 如何使用
azd config命令 -
azd config如何与其他azd功能集成
浏览 Azure 开发人员 CLI 配置文件
首次安装 Azure 开发人员 CLI 时,会在以下位置中添加名为 config.json 的文件:
- Linux 和 macOS 上的
$HOME/.azd - Windows 上的
%USERPROFILE%\.azd
提示
可以通过在 AZD_CONFIG_DIR 环境变量中指定路径来覆盖配置目录。
此文件中的设置用于管理一些功能,例如:
- 预配或部署资源时要使用的默认 Azure 订阅或位置
- 已启用哪些 Alpha 功能
- 配置了哪些模板源位置
- 用户为脚本或其他目的设置的自定义值
默认情况下,config.json 文件仅包含默认 azd 模板源位置的几个配置。 使用 Azure 开发人员 CLI 的各种功能时,某些值会自动在 config.json 中填充。 例如,首次运行 azd up 命令时,为预配和部署选择的订阅和位置存储在文件的 defaults 部分中。
简单的 config.json 文件可能如下所示:
{
"defaults": {
"location": "eastus2",
"subscription": "your-subscription-id"
},
"template": {
"sources": {
"awesome-azd": {
"key": "awesome-azd",
"location": "https://aka.ms/awesome-azd/templates.json",
"name": "Awesome AZD",
"type": "awesome-azd"
},
"default": {
"key": "default",
"name": "default"
}
}
}
}
使用配置命令
Azure 开发人员 CLI 提供一组命令,用于手动管理 config.json 文件中的设置:
-
azd config get:获取配置值。 -
azd config list-alpha:在 alpha 阶段显示可用功能的列表。 -
azd config reset:将配置重置为默认值。 -
azd config set:设置配置。 -
azd config show:显示所有配置值。 -
azd config unset:解除配置。
以下各节将更深入地探讨这些命令。 还可以访问 Azure 开发人员 CLI 命令 参考页,了解有关 azd 命令的详细信息。
显示配置
通过运行 config.json 命令随时查看整个 azd config show 文件的当前内容:
azd config show
示例输出:
{
"defaults": {
"location": "eastus2",
"subscription": "your-subscription-id"
},
"template": {
"sources": {
"awesome-azd": {
"key": "awesome-azd",
"location": "https://aka.ms/awesome-azd/templates.json",
"name": "Awesome AZD",
"type": "awesome-azd"
},
"default": {
"key": "default",
"name": "default"
}
}
}
}
使用 azd config get <key> 命令显示特定配置值:
azd config get defaults
示例输出:
"defaults": {
"location": "eastus2",
"subscription": "your-subscription-id"
}
启用或禁用 alpha 功能是一项常见的配置任务,因此 azd 还包括查看 alpha 功能的当前状态的便利命令:
azd config list-alpha
示例输出:
Name: aca.persistDomains
Description: Do not change custom domains when deploying Azure Container Apps.
Status: Off
Name: aca.persistIngressSessionAffinity
Description: Do not change Ingress Session Affinity when deploying Azure Container Apps.
Status: Off
Name: aks.helm
Description: Enable Helm support for AKS deployments.
Status: On
Name: aks.kustomize
Description: Enable Kustomize support for AKS deployments.
Status: Off
Name: azd.operations
Description: Extends provisioning providers with azd operations.
Status: Off
Name: deployment.stacks
Description: Enables Azure deployment stacks for ARM/Bicep based deployments.
Status: Off
Name: llm
Description: Enables the use of LLMs in the CLI.
Status: Off
获取和设置配置
可以使用 config.json 命令在 azd config 文件中获取、设置或取消设置值。 其他 azd 功能和命令使用某些特定配置,例如启用 alpha 功能或设置模板源时,也可以设置自己的自定义值。
管理 azd 使用的配置
使用 azd config set <key> <value> 命令将配置设置添加到 config.json 文件。
例如,若要启用GitHub Copilot集成使用的 LLM 功能,请执行以下操作:
azd config set alpha.llm on
注意
在 期间选择azd init将自动启用此设置。 获取和设置配置值时,使用 . 语法遍历 JSON 对象结构。
使用 azd config get <key> 命令验证是否已启用设置,例如:
azd config get alpha.llm
示例输出:
"on"
在此方案中,还可以运行 azd config get alpha 来查看 config.json 文件中的整个 JSON 对象:
azd config get alpha
示例输出:
{
"llm": "on"
}
管理自定义配置
可以设置自定义配置值以便在 azd 挂钩和客户脚本中使用。 这些配置值提供了使用环境变量的替代方法。
要设置一个自定义配置值:
azd config get customVal hello-world
获取自定义配置值:
azd config get customVal
示例输出:
hello-world
重置配置
可以使用 config.json 命令将 Azure 开发人员 CLI azd config reset 文件重置回其默认值,该命令会删除该文件的内容:
azd config reset
重置后运行 azd config show 时,将只看到一个空对象:
{}