Proposed Pull Request Change

title description ms.topic ms.date ms.custom
Bicep CLI commands Learn about the commands that you can use in the Bicep CLI. These commands include building JSON Azure Resource Manager templates from Bicep. reference 12/02/2025 devx-track-azurecli, devx-track-bicep, devx-track-arm-template
📄 Document Links
GitHub View on GitHub Microsoft Learn View on Microsoft Learn
Raw New Markdown
Generating updated version of doc...
Rendered New Markdown
Generating updated version of doc...
+0 -0
+0 -0
--- title: Bicep CLI commands description: Learn about the commands that you can use in the Bicep CLI. These commands include building JSON Azure Resource Manager templates from Bicep. ms.topic: reference ms.date: 12/02/2025 ms.custom: devx-track-azurecli, devx-track-bicep, devx-track-arm-template --- # Bicep CLI commands This article describes the commands you can use in the Bicep CLI. You can execute these commands by using the Azure CLI or by directly invoking Bicep CLI commands. Each method requires a distinct installation process. For more information about installations, see [Azure CLI](./install.md#azure-cli) and [Azure PowerShell](./install.md#azure-powershell). This guidance shows how to run the commands in the Azure CLI. When running commands in the Azure CLI, start them with `az`. If you're not using the Azure CLI, run the commands without `az` at the start of each. For example, `az bicep build` becomes `bicep build`, and `az bicep version` becomes `bicep --version`. ## build The `build` command converts a Bicep file to a JSON Azure Resource Manager template (ARM template). Typically, you don't need to run this command because it runs automatically when you deploy a Bicep file. Run it manually when you want to see the JSON ARM template that's created from your Bicep file. Using any of following Bicep features automatically enables language version 2.0 code generation: * [user-defined types](../bicep/user-defined-data-types.md) * [user-defined functions](../bicep/user-defined-functions.md) * [compile-time imports](../bicep/bicep-import.md) * [experimental features](../bicep/bicep-config.md#enable-experimental-features) The following example converts a Bicep file named _main.bicep_ to an ARM template named _main.json_. The new file is created in the same directory as the Bicep file: # [Bicep CLI](#tab/bicep-cli) ```bicepcli bicep build main.bicep ``` # [Azure CLI](#tab/azure-cli) ```azurecli az bicep build --file main.bicep ``` --- The next example saves _main.json_ to a different directory: # [Bicep CLI](#tab/bicep-cli) ```bicepcli bicep build main.bicep --outdir c:\jsontemplates ``` # [Azure CLI](#tab/azure-cli) ```azurecli az bicep build --file main.bicep --outdir c:\jsontemplates ``` --- The next example specifies the name and location of the file to be created: # [Bicep CLI](#tab/bicep-cli) ```bicepcli bicep build main.bicep --outfile c:\jsontemplates\azuredeploy.json ``` # [Azure CLI](#tab/azure-cli) ```azurecli az bicep build --file main.bicep --outfile c:\jsontemplates\azuredeploy.json ``` --- To print the file to `stdout`, use: # [Bicep CLI](#tab/bicep-cli) ```bicepcli bicep build main.bicep --stdout ``` # [Azure CLI](#tab/azure-cli) ```azurecli az bicep build --file main.bicep --stdout ``` --- If your Bicep file includes a module that references an external registry, the `build` command automatically calls [`restore`](#restore). The `restore` command gets the file from the registry and stores it in the local cache. > [!NOTE] > The `restore` command doesn't refresh the cache. For more information, see [restore](#restore). To not call restore automatically, use the `--no-restore` switch: # [Bicep CLI](#tab/bicep-cli) ```bicepcli bicep build --no-restore <bicep-file> ``` To use the `--no-restore` switch, you must have [Bicep CLI](./install.md#visual-studio-code-and-bicep-extension) version 0.4.X or later. # [Azure CLI](#tab/azure-cli) ```azurecli az bicep build --no-restore <bicep-file> ``` --- The build process with the `--no-restore` switch fails if one of the external modules isn't already cached: ```error The module with reference "br:exampleregistry.azurecr.io/bicep/modules/storage:v1" hasn't been restored. ``` When you get this error, either run the `build` command without the `--no-restore` switch, or run `bicep restore` first. ## build-params The `build-params` command builds a `.bicepparam` file into a JSON parameters file: # [Bicep CLI](#tab/bicep-cli) ```bicepcli bicep build-params params.bicepparam ``` # [Azure CLI](#tab/azure-cli) ```azurecli az bicep build-params --file params.bicepparam ``` --- This command converts a _params.bicepparam_ parameters file into a _params.json_ JSON parameters file. ## decompile The `decompile` command converts a JSON ARM template to a Bicep file: # [Bicep CLI](#tab/bicep-cli) ```bicepcli bicep decompile main.json ``` # [Azure CLI](#tab/azure-cli) ```azurecli az bicep decompile --file main.json ``` --- This command creates a file named _main.bicep_ in the same directory as _main.json_. If _main.bicep_ exists in the same directory, use the **--force** switch to overwrite the existing Bicep file. For more information about using this command, see [Decompile JSON ARM template to Bicep](decompile.md). ## decompile-params The `decompile-params` command decompiles a JSON parameters file to a `.bicepparam` parameters file. # [Bicep CLI](#tab/bicep-cli) ```bicepcli bicep decompile-params azuredeploy.parameters.json --bicep-file ./dir/main.bicep ``` # [Azure CLI](#tab/azure-cli) ```azurecli az bicep decompile-params --file azuredeploy.parameters.json --bicep-file ./dir/main.bicep ``` --- This command decompiles an _azuredeploy.parameters.json_ parameters file into an _azuredeploy.parameters.bicepparam_ file. `--bicep-file` specifies the path to the Bicep file (relative to the `.bicepparam` file) that's referenced in the `using` declaration. ## format The `format` command formats a Bicep file so that it follows the recommended style conventions. Think of it like a "code formatter" or "prettier" for your Bicep files. It has the same function as the `SHIFT+ALT+F` shortcut in Visual Studio Code. # [Bicep CLI](#tab/bicep-cli) ```bicepcli bicep format main.bicep ``` # [Azure CLI](#tab/azure-cli) ```azurecli az bicep format --file main.bicep ``` --- ## generate-params The `generate-params` command builds a parameters file from the given Bicep file, updates if there's an existing parameters file. # [Bicep CLI](#tab/bicep-cli) ```bicepcli bicep generate-params main.bicep --output-format bicepparam --include-params all ``` # [Azure CLI](#tab/azure-cli) ```azurecli az bicep generate-params --file main.bicep --output-format bicepparam --include-params all ``` --- This command creates a Bicep parameters file named _main.bicepparam_. The parameters file contains all parameters in the Bicep file, whether configured with default values or not. # [Bicep CLI](#tab/bicep-cli) ```bicepcli bicep generate-params main.bicep --outfile main.parameters.json ``` # [Azure CLI](#tab/azure-cli) ```azurecli az bicep generate-params --file main.bicep --outfile main.parameters.json ``` --- This command creates a parameters file named _main.parameters.json_. The parameters file only contains the parameters without default values configured in the Bicep file. ## install The `install` command adds the Bicep CLI to your local environment, and it's only available through the Azure CLI. For more information, see [Install Bicep tools](install.md). To install the latest version, use: # [Bicep CLI](#tab/bicep-cli) N/A # [Azure CLI](#tab/azure-cli) ```azurecli az bicep install ``` --- To install a specific version: # [Bicep CLI](#tab/bicep-cli) N/A # [Azure CLI](#tab/azure-cli) ```azurecli az bicep install --version v0.37.4 ``` --- ## jsonrpc The `jsonrpc` command enables running the Bicep CLI with a JSON-RPC interface, allowing for programmatic interaction with structured output and avoiding cold-start delays when compiling multiple files. This setup also supports building libraries to interact with Bicep files programmatically in non-.NET languages. The wire format for sending and receiving input/output is header-delimited, using the following structure, where `\r` and `\n` represent carriage return and line feed characters: ``` Content-Length: <length>\r\n\r\n<message>\r\n\r\n ``` * `<length>` is the length of the `<message>` string, including the trailing `\r\n\r\n`. * `<message>` is the raw JSON message. For example: ``` Content-Length: 72\r\n\r\n{"jsonrpc": "2.0", "id": 0, "method": "bicep/version", "params": {}}\r\n\r\n ``` The following methods are available through the JSON-RPC interface: * **bicep/format** Formats a Bicep file. * The request: ```json { "jsonrpc": "2.0", "id": 1, "method": "bicep/format", "params": { "path": "/path/to/file.bicep" } } ``` * The response: ```json { "jsonrpc": "2.0", "id": 1, "result": { "success": true, "diagnostics": [], "contents": "param foo string\n\nresource storage 'Microsoft.Storage/storageAccounts@2025-01-01' = {\n name: 'mystorageaccount'\n location: 'East US'\n}\n" } } ``` On success, `"success": true` is returned, with contents holding the formatted Bicep source. On failure, `"success": false` with `diagnostics` describing the failure. * **bicep/version** Returns the version of the Bicep CLI. * The request: ```json { "jsonrpc": "2.0", "id": 0, "method": "bicep/version", "params": {} } ``` * The response: ```json { "jsonrpc": "2.0", "id": 0, "result": { "version": "0.24.211" } } ``` For the available methods & request/response bodies, see [`ICliJsonRpcProtocol.cs`](https://github.com/Azure/bicep/blob/main/src/Bicep.Cli/Rpc/ICliJsonRpcProtocol.cs). For an example establishing a JSONRPC connection and interacting with Bicep files programmatically using Node, see [`jsonrpc.test.ts`](https://github.com/Azure/bicep/blob/main/src/Bicep.Cli.E2eTests/src/local/jsonrpc.test.ts). ### Usage for named pipe Use the following syntax to connect to an existing named pipe as a JSONRPC client: # [Bicep CLI](#tab/bicep-cli) ```bicep cli bicep jsonrpc --pipe <named_pipe>` ``` `<named_pipe>` is an existing named pipe to connect the JSONRPC client to. # [Azure CLI](#tab/azure-cli) N/A --- To connect to a named pipe on OSX/Linux: # [Bicep CLI](#tab/bicep-cli) ```bicep cli bicep jsonrpc --pipe /tmp/bicep-81375a8084b474fa2eaedda1702a7aa40e2eaa24b3.sock ``` # [Azure CLI](#tab/azure-cli) N/A --- To connect to a named pipe on Windows: # [Bicep CLI](#tab/bicep-cli) ```bicep cli bicep jsonrpc --pipe \\.\pipe\\bicep-81375a8084b474fa2eaedda1702a7aa40e2eaa24b3.sock` ``` # [Azure CLI](#tab/azure-cli) N/A --- For more examples, see [C#](https://github.com/Azure/bicep/blob/096c32f9d5c42bfb85dff550f72f3fe16f8142c7/src/Bicep.Cli.IntegrationTests/JsonRpcCommandTests.cs#L24-L50) and [node.js](https://github.com/anthony-c-martin/bicep-node/blob/4769e402f2d2c1da8d27df86cb3d62677e7a7456/src/utils/jsonrpc.ts#L117-L151). ### Usage for TCP socket Use the following syntax to connect to an existing TCP socket as a JSONRPC client: # [Bicep CLI](#tab/bicep-cli) ```bicep cli bicep jsonrpc --socket <tcp_socket> ``` `<tcp_socket>` is the socket number to which the JSONRPC client connects. # [Azure CLI](#tab/azure-cli) N/A --- To connect to a TCP socket: # [Bicep CLI](#tab/bicep-cli) ```bicep cli bicep jsonrpc --socket 12345 ``` # [Azure CLI](#tab/azure-cli) N/A --- ### Usage for stdin and stdout Use the following syntax and `stdin` and `stdout` for messages to run the JSONRPC interface: # [Bicep CLI](#tab/bicep-cli) ```bicep cli bicep jsonrpc --stdio ``` # [Azure CLI](#tab/azure-cli) N/A --- ## lint The `lint` command returns the errors and [linter rule](./linter.md) violations of a Bicep file. # [Bicep CLI](#tab/bicep-cli) ```bicepcli bicep lint main.bicep ``` # [Azure CLI](#tab/azure-cli) ```azurecli az bicep lint --file main.bicep ``` --- If your Bicep file includes a module that references an external registry, the `lint` command automatically calls [`restore`](#restore). The `restore` command gets the file from the registry and stores it in the local cache. > [!NOTE] > The `restore` command doesn't refresh the cache. For more information, see [restore](#restore). To not call restore automatically, use the `--no-restore` switch: # [Bicep CLI](#tab/bicep-cli) ```bicepcli bicep lint --no-restore <bicep-file> ``` # [Azure CLI](#tab/azure-cli) ```azurecli az bicep lint --no-restore <bicep-file> ``` --- The lint process with the `--no-restore` switch fails if one of the external modules isn't already cached: ```error The module with reference "br:exampleregistry.azurecr.io/bicep/modules/storage:v1" has not been restored. ``` When you get this error, either run the `lint` command without the `--no-restore` switch or run `bicep restore` first. ## list-versions The `list-versions` command returns all available versions of the Bicep CLI. Use this command to see if you want to [upgrade](#upgrade) or [install](#install) a new version. This command is only available through the Azure CLI. # [Bicep CLI](#tab/bicep-cli) N/A # [Azure CLI](#tab/azure-cli) ```azurecli az bicep list-versions ``` The command returns an array of available versions: ```console [ "v0.37.4", "v0.36.177", "v0.36.1", "v0.35.1", "v0.34.44", "v0.34.1", "v0.33.93", "v0.33.13", "v0.32.4", "v0.31.92", "v0.31.34", "v0.30.23", "v0.30.3", "v0.29.47", "v0.29.45", "v0.28.1", "v0.27.1", "v0.26.170", "v0.26.54", "v0.25.53", "v0.25.3", "v0.24.24", "v0.23.1", "v0.22.6", "v0.21.1", "v0.20.4", "v0.19.5", "v0.18.4", "v0.17.1", "v0.16.2" ] ``` --- ## publish The `publish` command adds a module to a registry. The Azure container registry must exist and the account publishing to the registry must have the correct permissions. For more information about setting up a module registry, see [Use private registry for Bicep modules](private-module-registry.md). To publish a module, the account must have the correct profile and permissions to access the registry. You can configure the profile and credential precedence for authenticating to the registry in the [Bicep config file](./bicep-config-modules.md#configure-profiles-and-credentials). After publishing the file to the registry, you can [reference it in a module](modules.md#file-in-registry). You must have [Bicep CLI](./install.md#visual-studio-code-and-bicep-extension) version 0.14.X or later to use the `publish` command and the `--documentationUri`/`-d` parameter. To publish a module to a registry, use: # [Bicep CLI](#tab/bicep-cli) ```bicepcli bicep publish <bicep-file> --target br:<registry-name>.azurecr.io/<module-path>:<tag> --documentationUri <documentation-uri> ``` # [Azure CLI](#tab/azure-cli) ```azurecli az bicep publish --file <bicep-file> --target br:<registry-name>.azurecr.io/<module-path>:<tag> --documentationUri <documentation-uri> ``` --- For example: # [Bicep CLI](#tab/bicep-cli) ```bicepcli bicep publish storage.bicep --target br:exampleregistry.azurecr.io/bicep/modules/storage:v1 --documentationUri https://www.contoso.com/exampleregistry.html ``` # [Azure CLI](#tab/azure-cli) ```azurecli az bicep publish --file storage.bicep --target br:exampleregistry.azurecr.io/bicep/modules/storage:v1 --documentationUri https://www.contoso.com/exampleregistry.html ``` --- The `publish` command doesn't recognize aliases specified in a [_bicepconfig.json_ file](bicep-config-modules.md). Provide the full module path. > [!WARNING] > Publishing to the same target overwrites the old module. We recommend that you increment the version when updating. ## restore When your Bicep file uses modules that are published to a registry, the `restore` command gets copies of all the required modules from the registry. It stores those copies in a local cache. A Bicep file can only be built when the external files are available in the local cache. Normally, running restore isn't necessary as it's automatically triggered by the build process. To restore external modules to the local cache, the account must have the correct profile and permissions to access the registry. You can configure the [profile and credential precedence](./bicep-config-modules.md#configure-profiles-and-credentials) for authenticating to the registry in the Bicep config file. To use the `restore` command, you must have [Bicep CLI](./install.md#visual-studio-code-and-bicep-extension) version 0.14.X or later. To manually restore the external modules for a file, use: ### [Bicep CLI](#tab/bicep-cli) ```bicepcli bicep restore <bicep-file> ``` ### [Azure CLI](#tab/azure-cli) ```azurecli az bicep restore --file <bicep-file> [--force] ``` --- The Bicep file you provide is the file you wish to deploy. It must contain a module that links to a registry. For example, you can restore the following file: ```bicep module stgModule 'br:exampleregistry.azurecr.io/bicep/modules/storage:v1' = { name: 'storageDeploy' params: { storagePrefix: 'examplestg1' } } ``` The local cache is found in: * On Windows ```path %USERPROFILE%\.bicep\br\<registry-name>.azurecr.io\<module-path\<tag> ``` * On Linux ```path /home/<username>/.bicep ``` * On Mac ```path ~/.bicep ``` The `restore` command doesn't refresh the cache if a module is already cached. To refresh the cache, you can either delete the module path from the cache or use the `--force` switch with the `restore` command. ## upgrade The `upgrade` command updates your installed version with the latest version. This command is only available through the Azure CLI. # [Bicep CLI](#tab/bicep-cli) N/A # [Azure CLI](#tab/azure-cli) ```azurecli az bicep upgrade ``` --- ## version The `version` command returns your installed version: # [Bicep CLI](#tab/bicep-cli) ```bicepcli bicep --version ``` If the Bicep CLI hasn't been installed, you'll see an error message stating that the Bicep CLI wasn't found. # [Azure CLI](#tab/azure-cli) ```azurecli az bicep version ``` --- The command shows the version number: ```console Bicep CLI version 0.29.45 (57a44c0230) ``` ## Next steps To learn more about deploying a Bicep file, see: * [Deploy - Azure CLI](deploy-cli.md) * [Deploy - Azure PowerShell](deploy-powershell.md) * [Deploy - Cloud Shell](deploy-cloud-shell.md)
Success! Branch created successfully. Create Pull Request on GitHub
Error: