Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
This article describes the commands you can use in the Bicep CLI.
You can run Bicep commands in two ways:
- Standalone Bicep CLI: Run
bicep <command>. You must install the Bicep CLI manually. Azure PowerShell also uses the standalone Bicep CLI. - Azure CLI: Run
az bicep <command>. The Azure CLI installs and manages its own copy of the Bicep CLI, and doesn't add it to yourPATH. For the full list of Azure CLI parameters, see az bicep.
The two interfaces use different syntax. The standalone Bicep CLI takes the input file as a positional argument, while the Azure CLI requires the --file parameter:
| Standalone Bicep CLI | Azure CLI |
|---|---|
bicep build main.bicep |
az bicep build --file main.bicep |
bicep lint main.bicep |
az bicep lint --file main.bicep |
bicep --version |
az bicep version |
| Not available | az bicep install, az bicep upgrade, az bicep list-versions, az bicep uninstall |
Some standalone options, such as --pattern and --config, don't have an az bicep equivalent. To use them from the Azure CLI, use az bicep run (Azure CLI 2.88.0 or later) to pass the command directly to the Bicep CLI:
az bicep run --command "build main.bicep --config ./bicepconfig.prod.json"
Common options
Global options
The following options are available on the bicep command itself:
| Option | Description |
|---|---|
--version, -v |
Shows the Bicep CLI version. |
--help, -h, -? |
Shows help. Add it after any command to show help for that command, for example bicep build --help. |
--license |
Prints license information. |
--third-party-notices |
Prints third-party notices. |
Process multiple files
The build, build-params, format, lint, and restore commands accept a --pattern option that processes every file matching a glob pattern instead of a single input file. Specify either an input file or --pattern, not both. Quote the pattern so that your shell doesn't expand it:
bicep build --pattern './**/*.bicep'
bicep lint --pattern './modules/*.bicep'
The pattern is resolved relative to the current directory. When you use --pattern:
--stdoutand--outfilearen't supported.buildandbuild-paramssupport--outdir, and preserve the relative folder structure of the matched files under the output directory.formatdoesn't support--outdirand formats each matched file in place.
The Azure CLI az bicep commands don't support --pattern. Use az bicep run instead.
Output diagnostics as SARIF
The build, build-params, and lint commands accept --diagnostics-format with a value of default or sarif. Use sarif to produce diagnostics as a SARIF 2.1.0 log that code-scanning tools can consume:
bicep lint main.bicep --diagnostics-format sarif > lint.sarif
The lint command writes the SARIF log to standard output. The build command writes the SARIF log to standard error.
In the Azure CLI, only az bicep lint supports --diagnostics-format.
Use a specific configuration file
Starting in Bicep CLI v0.49, most commands accept --config <path> to use a specific configuration file instead of automatic bicepconfig.json discovery:
bicep build main.bicep --config ./bicepconfig.prod.json
The az bicep commands don't support --config. Use az bicep run instead. For details about how the configuration file is applied, see Specify a configuration file in the Bicep CLI.
Control output location
Commands that write files accept the following options. Unless noted otherwise, the output file is written next to the input file with the same base name.
| Option | Description |
|---|---|
--outdir <dir> |
Writes the output file to the specified directory. |
--outfile <path> |
Writes the output to the specified file path. |
--stdout |
Prints the output to standard output instead of writing a file. |
Restore external modules
Commands that compile Bicep files automatically restore modules that reference an external registry. Use --no-restore to skip the restore. The command fails if an external module isn't already in the local cache:
The module with reference "br:exampleregistry.azurecr.io/bicep/modules/storage:v1" hasn't been restored.
When you get this error, either run the command without --no-restore or run bicep restore first.
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 the following Bicep features automatically enables language version 2.0 code generation:
bicep build [<bicep-file>] [options]
| Option | Description |
|---|---|
--outdir, --outfile, --stdout |
Control where the template is written. See Control output location. |
--pattern <glob> |
Builds all files that match the pattern. See Process multiple files. |
--no-restore |
Builds without restoring external modules. |
--diagnostics-format <default\|sarif> |
Sets the diagnostics format. |
--config <path> |
Uses the specified configuration file. |
The following example converts a Bicep file named main.bicep to an ARM template named main.json in the same directory:
The next example saves main.json to a different directory:
The following example specifies the name and location of the file to create:
To print the template to stdout, use:
To build every Bicep file under the current directory and write the templates to a build directory, use --pattern:
If your Bicep file includes a module that references an external registry, the build command automatically calls restore. To prevent automatic restore, use --no-restore. For more information, see Restore external modules.
build-params
The build-params command builds a .bicepparam file into a JSON parameters file.
bicep build-params [<bicepparam-file>] [options]
| Option | Description |
|---|---|
--outdir, --outfile |
Control where the JSON parameters file is written. Only the parameters file is written; the referenced Bicep file isn't included. |
--stdout |
Prints both the compiled parameters and the compiled template that the using declaration references. See Standard output format. |
--pattern <glob> |
Builds all files that match the pattern. See Process multiple files. |
--bicep-file <path> |
Verifies that the specified Bicep file matches the file in the using declaration. The command fails if the files don't match. This option doesn't change which Bicep file is used. |
--no-restore |
Builds without restoring external modules. |
--diagnostics-format <default\|sarif> |
Sets the diagnostics format. |
--config <path> |
Uses the specified configuration file. |
The following example converts a params.bicepparam parameters file into a params.json JSON parameters file:
The following example writes the JSON parameters file to a specific path:
Standard output format
With --stdout, the command prints a JSON object instead of a plain parameters file. Use this output when you need both the parameters and the template, for example in a deployment script:
{
"parametersJson": "{\"$schema\": \"https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#\", ...}",
"templateJson": "{\"$schema\": \"https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#\", ...}",
"templateSpecId": null
}
| Property | Description |
|---|---|
parametersJson |
The compiled parameters file, serialized as a JSON string. |
templateJson |
The compiled template that the using declaration references, serialized as a JSON string. |
templateSpecId |
The resource ID of the template spec when the using declaration references one; otherwise null. |
Because parametersJson and templateJson are strings, parse them separately. For example, in PowerShell:
$output = bicep build-params params.bicepparam --stdout | ConvertFrom-Json
$parameters = $output.parametersJson | ConvertFrom-Json
console
The console command is available in Bicep CLI v0.42.1 or later. It opens an interactive Read-Eval-Print Loop (REPL) where you can evaluate Bicep expressions, declare variables, and test functions and user-defined types without deploying. It also accepts piped or redirected input.
bicep console [--config <path>]
To exit the console, press ESC or enter exit. The console command isn't available in the Azure CLI.
For features, limitations, and examples, see Evaluate expressions with the Bicep console.
decompile
The decompile command converts a JSON ARM template to a Bicep file.
bicep decompile [<json-file>] [options]
| Option | Description |
|---|---|
--outdir, --outfile, --stdout |
Control where the Bicep file is written. See Control output location. |
--force |
Overwrites the output file if it exists. Without this option, the command fails if the output file exists. |
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.
az bicep decompile supports only --force. To use the output options from the Azure CLI, use az bicep run.
For more information about using this command, see Decompile JSON ARM template to Bicep.
decompile-params
The decompile-params command decompiles a JSON parameters file to a .bicepparam parameters file.
bicep decompile-params <json-file> [options]
| Option | Description |
|---|---|
--bicep-file <path> |
The Bicep file, relative to the .bicepparam file, to reference in the using declaration. |
--outdir, --outfile, --stdout |
Control where the .bicepparam file is written. See Control output location. |
--force |
Overwrites the output file if it exists. |
bicep decompile-params azuredeploy.parameters.json --bicep-file ./dir/main.bicep
This command decompiles an azuredeploy.parameters.json parameters file into an azuredeploy.parameters.bicepparam file.
format
The format command formats a Bicep file so that it follows the recommended style conventions. Think of it as a code formatter or "prettier" for your Bicep files. It has the same function as the SHIFT+ALT+F shortcut in Visual Studio Code.
By default, the command formats the file in place.
bicep format [<bicep-file>] [options]
| Option | Description |
|---|---|
--outdir, --outfile, --stdout |
Write the formatted file somewhere other than the input file. See Control output location. |
--pattern <glob> |
Formats all matching files in place. See Process multiple files. |
--newline-kind <LF\|CRLF\|CR> |
Sets the line-ending characters. |
--indent-kind <Space\|Tab> |
Sets the indentation kind. |
--indent-size <number> |
Sets the number of spaces for each indentation level. Valid only when --indent-kind is Space. |
--insert-final-newline |
Inserts a final newline at the end of the file. |
--config <path> |
Uses the specified configuration file. |
The following example formats a file with two-space indentation and LF line endings, and prints the result instead of changing the file:
bicep format main.bicep --indent-kind Space --indent-size 2 --newline-kind LF --stdout
To format every Bicep file under the current directory, use:
bicep format --pattern './**/*.bicep'
generate-params
The generate-params command builds a parameters file from the given Bicep file.
bicep generate-params [<bicep-file>] [options]
| Option | Description |
|---|---|
--output-format <json\|bicepparam> |
Sets the format of the parameters file. The default is json. |
--include-params <requiredonly\|all> |
Sets which parameters to include. requiredonly, the default, includes only parameters without a default value. all also includes parameters that have a default value. |
--outdir, --outfile, --stdout |
Control where the parameters file is written. See Control output location. |
--no-restore |
Generates the file without restoring external modules. |
--config <path> |
Uses the specified configuration file. |
By default, the output file is named <bicep-file-name>.parameters.json for JSON output, or <bicep-file-name>.bicepparam for .bicepparam output.
If a JSON parameters file already exists at the output path, the command keeps the values that are already in the file. When the output format is bicepparam, the command regenerates the file, and values in an existing .bicepparam file aren't kept.
bicep generate-params 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.
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.
jsonrpc
The jsonrpc command launches the Bicep CLI with a JSON-RPC interface, enabling fast programmatic interaction with Bicep files.
bicep jsonrpc --pipe <named-pipe>
bicep jsonrpc --socket <tcp-port>
bicep jsonrpc --stdio
For the wire format, available methods, and connection options, see Programmatic Bicep usage with JSON-RPC.
lint
The lint command returns the errors and linter rule violations of a Bicep file.
bicep lint [<bicep-file>] [options]
| Option | Description |
|---|---|
--pattern <glob> |
Lints all files that match the pattern. See Process multiple files. |
--no-restore |
Lints without restoring external modules. |
--diagnostics-format <default\|sarif> |
Sets the diagnostics format. With sarif, the SARIF log is written to standard output. |
--config <path> |
Uses the specified configuration file. |
The command returns exit code 1 if any diagnostic has the error level, and 0 otherwise. To make a linter rule fail the command, set its level to error in the linter configuration.
To lint every Bicep file under the current directory, use --pattern:
The following example saves the results as a SARIF log, for example to upload to a code-scanning tool in a CI pipeline:
To lint a file with a specific Bicep configuration file (Bicep CLI v0.49 or later), use --config:
If your Bicep file includes a module that references an external registry, the lint command automatically calls restore. To prevent automatic restore, use --no-restore. For more information, see Restore external modules.
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. You can configure the profile and credential precedence for authenticating to the registry in the Bicep config file.
After publishing the file to the registry, you can reference it in a module.
bicep publish <bicep-file> --target <module-reference> [options]
| Option | Description |
|---|---|
--target <module-reference> |
Required. The registry location to publish to, for example br:<registry-name>.azurecr.io/<module-path>:<tag>. |
--documentation-uri <uri> |
A URI for the module's documentation. Must be an absolute URI. |
--force |
Overwrites the module if the target tag already exists. |
--no-restore |
Publishes without restoring external modules. |
--config <path> |
Uses the specified configuration file. |
To publish a module to a registry, use:
bicep publish storage.bicep --target br:exampleregistry.azurecr.io/bicep/modules/storage:v1 --documentation-uri https://www.contoso.com/exampleregistry.html
If you define a registry alias in your bicepconfig.json file, you can use the alias in the target:
bicep publish storage.bicep --target br/CoreModules:storage:v1
If the target tag already exists, the command fails. To overwrite the existing module, use --force. Because the cached copy of a module isn't refreshed until a consumer forces a restore, different users can end up with different versions of an overwritten tag. Prefer publishing a new tag when you change a module.
bicep publish storage.bicep --target br:exampleregistry.azurecr.io/bicep/modules/storage:v1 --force
restore
When your Bicep file uses modules that you publish 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.
You don't need to call restore explicitly. Commands that compile Bicep files, such as build, build-params, lint, and publish, restore any missing modules automatically, as do deployments from the Azure CLI and Azure PowerShell. Run restore explicitly when you want to download modules in a separate step, for example before running other commands with --no-restore, or to refresh cached modules with --force.
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 for authenticating to the registry in the Bicep config file.
bicep restore [<bicep-file>] [options]
| Option | Description |
|---|---|
--pattern <glob> |
Restores modules for all files that match the pattern. See Process multiple files. |
--force |
Restores modules even if they're already cached, and retries modules that previously failed to restore. |
--config <path> |
Uses the specified configuration file. |
To manually restore the external modules for a file, use:
To restore the modules for every Bicep file under the current directory, use --pattern:
The Bicep file you provide is the file you want to deploy. It must contain a module that links to a registry. For example, you can restore the following file:
module stgModule 'br:exampleregistry.azurecr.io/bicep/modules/storage:v1' = {
name: 'storageDeploy'
params: {
storagePrefix: 'examplestg1'
}
}
You find the local cache in:
On Windows
%USERPROFILE%\.bicep\br\<registry-name>.azurecr.io\<module-path>\<tag>On Linux
/home/<username>/.bicepOn Mac
~/.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:
snapshot
The snapshot command, available in Bicep CLI v0.41.2 or later, creates a normalized, deterministic representation of the resources that a .bicepparam file deploys. You can compare the snapshot with later versions of your code to check what a refactor changes, without deploying anything to Azure. The evaluation runs locally, although restoring external modules can require network access.
For a walkthrough of creating baselines, testing refactors, and validating snapshots in CI, see Test Bicep changes with snapshots.
bicep snapshot <bicepparam-file> [options]
| Option | Description |
|---|---|
--mode <overwrite\|validate> |
overwrite, the default, writes the snapshot file. validate compares the current code with the existing snapshot file. |
--subscription-id, --resource-group, --location, --tenant-id, --management-group-id, --deployment-name |
Provide deployment context. See Provide context. |
--config <path> |
Uses the specified configuration file. |
Create a snapshot
The following command writes a <bicepparam-file-name>.snapshot.json file next to the .bicepparam file:
Validate changes
In validate mode, the command compares your current code with the saved snapshot and shows the differences. It returns exit code 1 if the snapshot file is missing or if the resources differ, so you can use it as a check in a CI pipeline.
A sample output looks like:
Snapshot validation failed. Expected no changes, but found the following:
Scope: <unknown>
~ [format('/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Storage/storageAccounts/stmyappstorage001', subscription().subscriptionId, resourceGroup().name)]
~ apiVersion: "2025-01-01" => "2025-06-01"
~ sku.name: "Standard_LRS" => "Standard_GRS"
Snapshots compare your code with a saved baseline. To compare a deployment with the resources that currently exist in Azure, use what-if.
Provide context
Because the snapshot command doesn't connect to Azure, it can't look up values such as your subscription ID or resource group name. If your code uses environment functions such as subscription().id, the snapshot contains unevaluated expressions unless you provide context through the following options:
| Argument | Purpose | Example Value |
|---|---|---|
--subscription-id |
Replaces the value returned by subscription().subscriptionId |
aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e |
--resource-group |
Replaces the value returned by resourceGroup().name |
my-production-rg |
--location |
Supplies resourceGroup().location when used with --resource-group, or deployment().location for deployments above resource-group scope |
westeurope |
--tenant-id |
Replaces the value returned by tenant().tenantId |
72f988bf-86f1-41af-91ab-2d7cd011db47 |
--management-group-id |
Replaces the value returned by managementGroup().name |
my-corp-mg |
--deployment-name |
Replaces the value returned by deployment().name |
snapshot-test |
bicep snapshot main.bicepparam \
--subscription-id 00000000-0000-0000-0000-000000000000 \
--resource-group my-temp-rg \
--location eastus \
--mode overwrite
Azure CLI management commands
The following commands manage the copy of the Bicep CLI that the Azure CLI uses. They're only available in the Azure CLI. For all parameters, see az bicep. For other installation methods, see Install Bicep tools.
install
The install command installs the Bicep CLI for use by the Azure CLI. To install the latest version, use:
az bicep install
To install a specific version, use the following command:
az bicep install --version v0.49.2
list-versions
The list-versions command returns all available versions of the Bicep CLI. Use this command to see if you want to upgrade or install a new version.
az bicep list-versions
The command returns an array of available versions, newest first:
[
"v0.49.2",
"v0.48.1",
...
]
upgrade
The upgrade command updates the Bicep CLI that the Azure CLI uses to the latest version.
az bicep upgrade
version
To show the installed version, use:
bicep --version
If you didn't install the Bicep CLI, you see an error message stating that the Bicep CLI wasn't found.
The command shows the version number:
Bicep CLI version 0.49.2 (b34271ac51)
Next steps
To learn more about deploying a Bicep file, see: