Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 19, 2025

Description

Bootstrap build failures in eng/build.ps1 were silently ignored, allowing the script to proceed to artifact cleanup and main build stages. This caused confusing downstream failures and wasted build time.

Added $lastExitCode check after bootstrap build invocation (line 399) to halt immediately on failure:

Invoke-Expression "& `"$PSScriptRoot/common/build.ps1`" $bootstrapArguments"

if ($lastExitCode -ne 0) {
  Write-Error "Bootstrap build failed. Stopping build."
  exit 1
}

Pattern matches existing failure handling in the script (lines 196-199, 215-218, 420-426) and aligns with build.sh behavior (set -ue).

Customer Impact

Developers see clear, immediate failure messages instead of confusing errors from subsequent build stages attempting to use broken bootstrap artifacts.

Regression

No. This fixes a long-standing issue in the bootstrap build path.

Testing

  • Verified pattern consistency with existing exit code checks in build.ps1
  • Demonstrated correct exit behavior with test scripts simulating bootstrap failures
  • PSScriptAnalyzer: no new issues introduced

Risk

Low. Adds defensive check that only triggers on actual bootstrap failures. No changes to success paths or build logic.

Original prompt

Problem

When the bootstrap build fails in eng/build.ps1, the script continues to clean up artifacts and proceed with the main build instead of halting. This can lead to confusing build failures and wasted build time.

Root Cause

After invoking the bootstrap build on line 391, there is no check for $lastExitCode to determine if the bootstrap build succeeded. The script unconditionally continues to the cleanup and main build stages even when the bootstrap build has failed.

Solution

Add an exit code check immediately after the bootstrap build invocation to halt the build process if the bootstrap build fails. This is consistent with how the script handles failures in the main build loop (lines 422-431).

Changes Required

In eng/build.ps1, after line 391 where the bootstrap build is invoked:

Invoke-Expression "& `"$PSScriptRoot/common/build.ps1`" $bootstrapArguments"

# ADD THIS CHECK:
if ($lastExitCode -ne 0) {
  Write-Error "Bootstrap build failed. Stopping build."
  exit 1
}

# Remove artifacts from the bootstrap build so the product build is a "clean" build.
Write-Host "Cleaning up artifacts from bootstrap build..."

This ensures that:

  1. If the bootstrap build fails ($lastExitCode -ne 0), an error message is displayed
  2. The script exits with code 1 (failure status)
  3. The cleanup and main build stages are never reached
  4. Developers get immediate, clear feedback about the bootstrap failure

File to Modify

  • eng/build.ps1 - Add exit code check after bootstrap build invocation (after line 391)

Testing

To test this fix:

  1. Force a bootstrap build failure (e.g., by temporarily breaking a bootstrap project)
  2. Run .\build.ps1 --bootstrap
  3. Verify that the build stops with an error message and doesn't proceed to cleanup or main build
  4. Verify that the exit code is 1 (failure)

This pull request was created from Copilot chat.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @dotnet/runtime-infrastructure
See info in area-owners.md if you want to be subscribed.

This change adds an exit code check immediately after the bootstrap build
invocation to halt the build process if the bootstrap build fails. This
prevents the script from continuing to cleanup and main build stages when
the bootstrap has failed, providing clear and immediate feedback to developers.

Fixes issue where bootstrap build failures were silently ignored and the
script would continue with cleanup and main build, leading to confusing
failures and wasted build time.

Co-authored-by: ericstj <8918108+ericstj@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix bootstrap build to halt on failure Add exit code check after bootstrap build in eng/build.ps1 Dec 19, 2025
Copilot AI requested a review from ericstj December 19, 2025 18:02
@ericstj ericstj requested a review from hoyosjs December 19, 2025 19:11
@ericstj ericstj marked this pull request as ready for review December 19, 2025 19:11
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

This PR adds a critical exit code check after the bootstrap build in eng/build.ps1 to prevent the script from continuing with artifact cleanup and main build stages when the bootstrap build fails. Previously, bootstrap build failures were silently ignored, leading to confusing downstream errors and wasted build time.

Key Changes

  • Added $lastExitCode validation immediately after bootstrap build invocation (lines 401-404)
  • Ensures script halts with clear error message on bootstrap failure
  • Aligns with existing error handling patterns used elsewhere in the same file

@ericstj ericstj requested review from jkoritzinsky and removed request for elinor-fung December 19, 2025 19:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

3 participants