-
Notifications
You must be signed in to change notification settings - Fork 726
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The linter is writing warnings to the standard error stream rather than the standard warning stream. #13995
Comments
As a workaround add a bicepconfig file to the repo or in a root folder on the agent with: https://learn.microsoft.com/en-us/azure/azure-resource-manager/bicep/bicep-config-linter |
Please note that "standard warning" is a purely powershell concept - there's no actual standard warning stream that a CLI application can use, so The exit code will tell you precisely whether a particular command has failed - personally I would recommend trying to use this instead to determine success. Here's how I would solve it personally - with the below you could then avoid using the param(
[Parameter(Mandatory = $true)]
[string[]]
$SearchPaths
)
$hasErrors = $false
function ExecSafe([scriptblock] $ScriptBlock) {
& $ScriptBlock
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to execute command: $ScriptBlock"
$hasErrors = $true
}
}
ExecSafe { az bicep version }
Write-Host `n'Building bicep files...'
foreach ($searchPath in $SearchPaths) {
Write-Host `n'Looking for resource files in:' $searchPath`n
$filesToBuild = Get-ChildItem Resources.bicep -Path $searchPath -Recurse -File
if ($filesToBuild.Length -eq 0) {
Write-Host 'Did not find any Resources.bicep files.' -ForegroundColor Red
}
foreach ($file in $filesToBuild) {
Write-Host 'Building:' $file.FullName
ExecSafe { az bicep build --file $file.FullName }
}
}
Write-Host `n'Finished building bicep files.'
if ($hasErrors) {
exit 1
} |
@mortenlerudjordet - Yes, but this then turns the warning off everywhere and not just in the one single permitted place. We still want the warning to happen elsewhere. @anthony-c-martin - Thanks for the additional info. I wasn't aware that powershell's "standard warning" was not a wrapper around an existing cmd one. I attempted to use your suggested code; however, I ran into the following error: That said, the real "meat" of the suggestion was to have the script to return a non-zero exit code when Since there is no "standard warning" at the cmd level and the root of my issue has been resolved via your suggestion, I've gone ahead and chosen to close this issue. Thank you 🙂 |
Bicep version
Bicep CLI version 0.26.170 (e9abaf1)
Describe the bug
The linter is writing warnings to the standard error stream rather than the standard warning stream.
It's possible that the issue is limited to only this rule:
Warning no-loc-expr-outside-params: Use a parameter here instead of 'resourceGroup().location'. 'resourceGroup().location' and 'deployment().location' should only be used as a default value for parameters. [https://aka.ms/bicep/linter/no-loc-expr-outside-params]
To Reproduce
Steps to reproduce the behavior:
az bicep build
Additional context
Add any other context about the problem here.
I have an ADO Pipeline that attempts to build a set of bicep files and verify that it is successful before allowing PRs to be merged. I updated the task to
failOnStderr: true
as the build sometimes passed even though theaz bicep build
command created errors. Now my pipeline is failing because of the above linting warning writing to Error Stream.Example Pipeline Task:
Example Powershell Script:
Example Bicep File with warning:
Example Pipeline Log:
The text was updated successfully, but these errors were encountered: