Skip to content

Fix build.ps1 to propagate exit codes#33896

Merged
rmarinho merged 2 commits intomainfrom
investigate/windows-packaged-tests
Feb 5, 2026
Merged

Fix build.ps1 to propagate exit codes#33896
rmarinho merged 2 commits intomainfrom
investigate/windows-packaged-tests

Conversation

@PureWeen
Copy link
Member

@PureWeen PureWeen commented Feb 4, 2026

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!

Description

Fixes an issue where eng/build.ps1 always exited with code 0 regardless of whether the underlying build succeeded or failed. This caused Azure Pipelines to show steps as "succeeded" even when they failed.

Problem

When running ./build.cmd -build (without -restore), if the .NET SDK is not found, the script would:

  1. Print "Unable to find dotnet with SDK version..."
  2. Call ExitWithExitCode 1 in tools.ps1
  3. But eng/build.ps1 would still exit with 0 (line 146: exit 0)

This caused Azure Pipelines to show the step as green/succeeded when it should have been red/failed.

Fix

  • Capture $LASTEXITCODE after Invoke-Expression call to common/build.ps1
  • Use the captured exit code instead of always exiting 0

Testing

This fix was identified while investigating Windows Helix device test failures where the "Build the MSBuild Tasks" step was showing as succeeded but had actually failed to find the SDK.

Build with the issue: https://dev.azure.com/dnceng-public/public/_build/results?buildId=1279950

Previously, eng/build.ps1 always exited with 0 regardless of whether
the underlying build succeeded or failed. This caused Azure Pipelines
to show steps as 'succeeded' even when they failed (e.g., when the
.NET SDK was not found).

The fix captures $LASTEXITCODE after Invoke-Expression and uses it
as the script's exit code instead of always exiting 0.
Copilot AI review requested due to automatic review settings February 4, 2026 18:42
@rmarinho
Copy link
Member

rmarinho commented Feb 4, 2026

@copilot we should fix this at upstream at dotnet/arcade repository, can you take care of that?

Copy link
Contributor

Copilot AI commented Feb 4, 2026

@rmarinho I've opened a new pull request, #33897, to work on those changes. Once the pull request is ready, I'll request review from you.

mattleibow
mattleibow previously approved these changes Feb 4, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

eng/build.ps1:120

  • Consider exiting early if the build fails, before attempting to run code coverage operations. If the build failed ($buildExitCode -ne 0), running tests and collecting coverage data is unlikely to succeed or provide useful information.

You could add a check immediately after line 115:

if ($buildExitCode -ne 0) {
  exit $buildExitCode
}

This would make the script fail fast and provide clearer error feedback. However, this is an optional enhancement and not blocking for this PR.



# Perform code coverage as the last operation, this enables the following scenarios:
#   .\build.cmd -restore -build -c Release -testCoverage
if ($testCoverage) {

The 'Install .NET' step runs with -restore which installs the SDK,
but environment variables don't persist between Azure DevOps steps.
The subsequent 'Build the MSBuild Tasks' step was running with just
-build, which doesn't install the SDK if missing.

Adding -restore ensures the SDK is properly available even in a new
PowerShell process.
@PureWeen
Copy link
Member Author

PureWeen commented Feb 5, 2026

/azp run maui-pr-uitests, maui-pr-devicetests

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants