@@ -129,8 +129,30 @@ function MergeHashes([hashtable] $source, [psvariable] $dest) {
129129 }
130130}
131131
132+ function IsBicepInstalled () {
133+ try {
134+ bicep -- version | Out-Null
135+ return $LASTEXITCODE -eq 0
136+ }
137+ catch {
138+ return $false
139+ }
140+ }
141+
142+ function IsAzCliBicepInstalled () {
143+ try {
144+ az bicep version | Out-Null
145+ return $LASTEXITCODE -eq 0
146+ }
147+ catch {
148+ return $false
149+ }
150+ }
151+
132152function BuildBicepFile ([System.IO.FileSystemInfo ] $file ) {
133- if (! (Get-Command bicep - ErrorAction Ignore)) {
153+ $useBicepCli = IsBicepInstalled
154+
155+ if (! $useBicepCli -and ! (IsAzCliBicepInstalled)) {
134156 Write-Error " A bicep file was found at '$ ( $file.FullName ) ' but the Azure Bicep CLI is not installed. See https://aka.ms/bicep-install"
135157 throw
136158 }
@@ -140,7 +162,12 @@ function BuildBicepFile([System.IO.FileSystemInfo] $file) {
140162
141163 # Az can deploy bicep files natively, but by compiling here it becomes easier to parse the
142164 # outputted json for mismatched parameter declarations.
143- bicep build $file.FullName -- outfile $templateFilePath
165+ if ($useBicepCli ) {
166+ bicep build $file.FullName -- outfile $templateFilePath
167+ } else {
168+ az bicep build -- file $file.FullName -- outfile $templateFilePath
169+ }
170+
144171 if ($LASTEXITCODE ) {
145172 Write-Error " Failure building bicep file '$ ( $file.FullName ) '"
146173 throw
@@ -150,13 +177,22 @@ function BuildBicepFile([System.IO.FileSystemInfo] $file) {
150177}
151178
152179function LintBicepFile ([string ] $path ) {
153- if (! (Get-Command bicep - ErrorAction Ignore)) {
154- Write-Error " A bicep file was found at '$path ' but the Azure Bicep CLI is not installed. See https://aka.ms/bicep-install"
155- throw
180+ $useBicepCli = IsBicepInstalled
181+
182+ if (! $useBicepCli -and ! (IsAzCliBicepInstalled)) {
183+ Write-Error " A bicep file was found at '$path ' but the Azure Bicep CLI is not installed. See https://aka.ms/bicep-install"
184+ throw
156185 }
157186
158187 # Work around lack of config file override: https://github.com/Azure/bicep/issues/5013
159- $output = bicep lint " $path " 2>&1
188+ $output = bicep lint $path 2>&1
189+
190+ if ($useBicepCli ) {
191+ $output = bicep lint $path 2>&1
192+ } else {
193+ $output = az bicep lint -- file $path 2>&1
194+ }
195+
160196 if ($LASTEXITCODE ) {
161197 Write-Error " Failed linting bicep file '$path '"
162198 throw
0 commit comments