Skip to content

Fix extension build.ps1 scripts to fail on any error#5739

Merged
JeffreyCA merged 2 commits intomainfrom
copilot/fix-5738
Sep 17, 2025
Merged

Fix extension build.ps1 scripts to fail on any error#5739
JeffreyCA merged 2 commits intomainfrom
copilot/fix-5738

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Sep 17, 2025

PowerShell build scripts for azd extensions were not properly failing when encountering errors, causing azd x build to report success even when builds failed due to missing dependencies or other issues.

The problem occurred because PowerShell scripts use $ErrorActionPreference = 'Continue' by default, which allows execution to continue after errors. Additionally, some critical setup commands like git rev-parse HEAD lacked proper error checking.

This resulted in scenarios where:

  • Go is not installed → go build fails → script continues → exits with code 0 (success)
  • Git command fails → script continues → exits with code 0 (success)
  • User sees "Build completed successfully!" even though the build actually failed

Changes made:

  1. Added $ErrorActionPreference = 'Stop' at the beginning of all 7 extension build.ps1 scripts to ensure any error stops execution immediately

  2. Added explicit error checking for git rev-parse HEAD commands to catch git failures early

  3. Preserved existing error handling for build commands (go build, dotnet publish, etc.) that was already in place

Files updated:

  • cli/azd/extensions/microsoft.azd.ai.builder/build.ps1
  • cli/azd/extensions/microsoft.azd.extensions/build.ps1
  • cli/azd/extensions/microsoft.azd.demo/build.ps1
  • cli/azd/extensions/microsoft.azd.extensions/internal/resources/languages/go/build.ps1
  • cli/azd/extensions/microsoft.azd.extensions/internal/resources/languages/python/build.ps1
  • cli/azd/extensions/microsoft.azd.extensions/internal/resources/languages/javascript/build.ps1
  • cli/azd/extensions/microsoft.azd.extensions/internal/resources/languages/dotnet/build.ps1

Now when any error occurs during extension building, the PowerShell scripts will properly exit with code 1, allowing azd x build to correctly detect and report the failure to users.

Fixes #5738.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: JeffreyCA <9157833+JeffreyCA@users.noreply.github.com>
Copilot AI changed the title [WIP] Update extension build.ps1 to fail on any error Fix extension build.ps1 scripts to fail on any error Sep 17, 2025
Copilot AI requested a review from JeffreyCA September 17, 2025 17:02
@JeffreyCA JeffreyCA changed the title Fix extension build.ps1 scripts to fail on any error Fix extension build.ps1 scripts to fail on any error Sep 17, 2025
@JeffreyCA JeffreyCA marked this pull request as ready for review September 17, 2025 17:04
@JeffreyCA JeffreyCA enabled auto-merge (squash) September 17, 2025 23:07
@JeffreyCA
Copy link
Copy Markdown
Contributor

/check-enforcer override

@JeffreyCA JeffreyCA merged commit 92143d4 into main Sep 17, 2025
40 of 45 checks passed
@JeffreyCA JeffreyCA deleted the copilot/fix-5738 branch September 17, 2025 23:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update extension build.ps1 to fail on any error

5 participants