Azure Developer CLI (azd) 允許你用一組azd config指令來管理azd設定。 這些設定包含有用的預設值,例如您的 Azure 訂閱與位置,以及其他azd指令或功能所使用的設定。 你也可以自訂自訂值,然後用在腳本或自訂功能裡。
在本文中,您將學到:
- 關於 Azure Developer CLI 配置的關鍵概念
- 如何操作
azd config指令 -
azd config如何與其他azd功能整合
探索 Azure Developer CLI 設定檔
當您首次安裝 Azure Developer CLI 時,會在以下位置新增一個名為 config.json CLI 的檔案:
-
$HOME/.azd在 Linux 和 macOS 上 -
%USERPROFILE%\.azd在 Windows 上
Tip
設定目錄可以透過在環境變數中指定路徑 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 Developer 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 整合所使用的大型語言模型功能:
azd config set alpha.llm on
備註
在 azd init 期間選取 使用 GitHub Copilot 設定(預覽) 會自動啟用此設定。 當你取得並設定設定值時,請使用 . 語法來遍歷 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 hooks 和客戶指令碼使用。 這些設定值提供了使用環境變數的替代方案。
要設定自訂設定值:
azd config get customVal hello-world
取得自訂設定值:
azd config get customVal
範例輸出:
hello-world
重置配置
你可以用以下azd config reset指令將 Azure Developer CLI config.json 檔案重設回預設,該指令會刪除檔案內容:
azd config reset
重置後執行 azd config show 時,你只會看到一個空物件:
{}