From fd258bdc93b7c0985a53c4444bb03b5d2a697edd Mon Sep 17 00:00:00 2001 From: nohwnd Date: Wed, 1 Jul 2026 23:08:50 +0200 Subject: [PATCH] Fail the build on failed HQRM blocks and containers Fail_Build_If_HQRM_Tests_Failed gated only on FailedCount, but a Pester 5 discovery/container failure (for example an empty -ForEach) does not increase FailedCount. It sets FailedContainersCount/FailedBlocksCount and marks the run Result as 'Failed', so the build wrongly passed as green. Gate on the Result property, which already accounts for failed tests, blocks and containers. This matches the container-aware check already used in the Invoke_HQRM_Tests task. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- CHANGELOG.md | 6 ++++++ .../Fail_Build_If_HQRM_Tests_Failed.build.ps1 | 14 +++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d8b98f56..f3baa9be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- `Fail_Build_If_HQRM_Tests_Failed` now fails the build when the Pester run + reports failed blocks or failed containers (for example a discovery failure + such as an empty `-ForEach`), not only when `FailedCount` is greater than zero. + Such container/discovery failures leave `FailedCount` at `0`, so the previous + gate let them pass as a green build. The task now gates on the Pester `Result` + property, matching the check already used in `Invoke_HQRM_Tests`. - Added tag `AllowSuppressMessageAttribute` to test `Should not suppress the required rule` to allow usage of `SuppressMessageAttribute` [#135](https://github.com/dsccommunity/DscResource.Test/issues/135). ## [0.19.0] - 2026-01-23 diff --git a/source/tasks/Fail_Build_If_HQRM_Tests_Failed.build.ps1 b/source/tasks/Fail_Build_If_HQRM_Tests_Failed.build.ps1 index bae6b1a0..ccd508a8 100644 --- a/source/tasks/Fail_Build_If_HQRM_Tests_Failed.build.ps1 +++ b/source/tasks/Fail_Build_If_HQRM_Tests_Failed.build.ps1 @@ -97,6 +97,18 @@ task Fail_Build_If_HQRM_Tests_Failed { { $DscTestObject = Import-Clixml -Path $DscTestResultObjectClixml -ErrorAction 'Stop' - Assert-Build -Condition ($DscTestObject.FailedCount -eq 0) -Message ('Failed {0} tests. Aborting Build.' -f $DscTestObject.FailedCount) + <# + A discovery/container failure (for example an empty -ForEach, or a + parse error in a test file) does not increase FailedCount. It is + reported through FailedContainersCount/FailedBlocksCount and the + overall Result. Gating on FailedCount alone therefore lets such + failures slip through as a green build. Gate on Result instead, which + already accounts for failed tests, blocks and containers. This mirrors + the check already used in the Invoke_HQRM_Tests task. + #> + $assertMessage = "Pester result was '{0}'. Failed {1} test(s), {2} block(s) and {3} container(s). Aborting Build." -f + $DscTestObject.Result, $DscTestObject.FailedCount, $DscTestObject.FailedBlocksCount, $DscTestObject.FailedContainersCount + + Assert-Build -Condition ($DscTestObject.Result -eq 'Passed') -Message $assertMessage } }