Skip to content
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

feat: Add input parameter to bicep build command that allows suppressing verbosity during execution #12653

Closed
AlexanderSehr opened this issue Dec 8, 2023 · 5 comments
Labels
enhancement New feature or request Needs: Triage 🔍

Comments

@AlexanderSehr
Copy link

Working recently on troubleshooting why something like $templatePaths | Foreach-Object -Parallel { bicep build $_ } would work for some Bicep templates but not for others I found out that the vebosity of the bicep build command seems to conflict with this kind of multithreading on Linux pipeline agents (I'm not able to reproduce this locally neither on Windows nor the WSL) - consistently.

The verbosity I'm referring to specifically are warnings returned by the template. For example /home/runner/work/bicep-registry-modules/bicep-registry-modules/avm/res/operational-insights/workspace/saved-search/main.bicep(44,5) : Warning BCP037: The property "etag" is not allowed on objects of type "SavedSearchProperties". No other properties are allowed. If this is an inaccuracy in the documentation, please report it to the Bicep Team. [https://aka.ms/bicep-type-issues] which is, unforatuntely, a false positive.

image

What happens using the above command is, that bicep build starts running in a thread, it prints the warning, and then the code goes into an 'error' state without an actual error to show for. To find out that it's because of the verbosity took a while:

While there is a 'workaround', that is, adding #disable-next-line to any line in question, there is a fair chance these issues will return each time e.g. the Bicep linter rules are updated.

To solve this for cases where I'm not interested in this verbositry (e.g., when I just want to build a dozen templates to statically test them) it would be very helpful if there would be a parameter to prevent the command from trying to write anything to the output/console stream. For example bicep build <path> --no-verbose.

@AlexanderSehr
Copy link
Author

This may or may not be related to #2334

@anthony-c-martin
Copy link
Member

It sounds like the powershell script or your CI pipeline is treating stderr as an indication that the command has failed? I would recommend instead checking the exit code to determine success or failure, and allowing stderr to be written to the normal error output channel.

If you're just looking to suppress stderr, then using 2> is a standard mechanism for doing this.
Powershell:

bicep build main.bicep --stdout 2>$null

Bash:

bicep build main.bicep --stdout 2>/dev/null

@AlexanderSehr
Copy link
Author

AlexanderSehr commented Dec 8, 2023

Dear @anthony-c-martin , thank you for the swift reply. Let me give that a shot. :)

@AlexanderSehr
Copy link
Author

So... the Bicep command really didn't like the --stderr: Unrecognized parameter "--stderr" :D Hence I'm not entirely sure how to check the exit code on this one.

Nethertheless - it did allow us to get past the issue. Thank you @anthony-c-martin :) If you happen to have a pointer regarding the stderr, let me know. :)

@anthony-c-martin
Copy link
Member

@AlexanderSehr I'll start by saying that I'm not a powershell expert. Generally, there are 3 things to check when you invoke a process: stdout, stderr, exit code.

My recommendation would be:

  • Check the exit code ($LASTEXITCODE in powershell) if you want to determine overall "Did the file compile successfully?"
  • You're already using stdout to capture the generated bicep file, which makes sense
  • Capture stderr and log it somewhere (this may help with troubleshooting - otherwise you may have a hard time understanding why a given file failed to build in the future)

Example of the approach I followed for accomplishing something similar in C# here:

  • Capture stdout & stderr to a variable
  • Check the exit code:
    • If 0, return the stdout, and log stderr to the "warning" channel
    • If non-0, throw an exception, and include stderr in the exception (to ensure it's logged)

Personally I'm not a PowerShell expert, so I'd have to defer to someone else to recommend how to accomplish this in Pwsh.

AlexanderSehr added a commit to Azure/bicep-registry-modules that referenced this issue Dec 8, 2023
…l to fail (#709)

## Description

Fixed issue where Bicep build output would cause Foreach-Parallel to
fail. This unblocks
- `operational-insights/workspace`
- `compute/virtual-machine`

Ref: Azure/bicep#12653

| Pipeline |
| - |
|
[![avm.res.operational-insights.workspace](https://github.com/AlexanderSehr/bicep-registry-modules/actions/workflows/avm.res.operational-insights.workspace.yml/badge.svg?branch=users%2Falsehr%2FthreadingTest_2)](https://github.com/AlexanderSehr/bicep-registry-modules/actions/workflows/avm.res.operational-insights.workspace.yml)
|

---------

Co-authored-by: Erika Gressi <56914614+eriqua@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Needs: Triage 🔍
Projects
Archived in project
Development

No branches or pull requests

2 participants