@@ -129,8 +129,30 @@ function MergeHashes([hashtable] $source, [psvariable] $dest) {
129
129
}
130
130
}
131
131
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
+
132
152
function BuildBicepFile ([System.IO.FileSystemInfo ] $file ) {
133
- if (! (Get-Command bicep - ErrorAction Ignore)) {
153
+ $useBicepCli = IsBicepInstalled
154
+
155
+ if (! $useBicepCli -and ! (IsAzCliBicepInstalled)) {
134
156
Write-Error " A bicep file was found at '$ ( $file.FullName ) ' but the Azure Bicep CLI is not installed. See https://aka.ms/bicep-install"
135
157
throw
136
158
}
@@ -140,7 +162,12 @@ function BuildBicepFile([System.IO.FileSystemInfo] $file) {
140
162
141
163
# Az can deploy bicep files natively, but by compiling here it becomes easier to parse the
142
164
# 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
+
144
171
if ($LASTEXITCODE ) {
145
172
Write-Error " Failure building bicep file '$ ( $file.FullName ) '"
146
173
throw
@@ -150,13 +177,22 @@ function BuildBicepFile([System.IO.FileSystemInfo] $file) {
150
177
}
151
178
152
179
function 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
156
185
}
157
186
158
187
# 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
+
160
196
if ($LASTEXITCODE ) {
161
197
Write-Error " Failed linting bicep file '$path '"
162
198
throw
0 commit comments