azure-dev: Set "continueOnError" to `false` script errors cant't stop execution of AZD in Windows

Describe the issue: For azd hook test, when set the “continueOnError” flag to false, script errors can not control stop execution of AZD. example as follow: image

Repro Steps:

  1. Clone template todo-nodejs-mongo to local.
  2. Add hook config in azure.yaml (Execute a script with errors).

image

  1. Run azd command to trigger hook.(eg. azd package)

Environment:

Expected behavior: When set the “continueOnError” flag to false, script errors can control stop execution of AZD

@rajeshkamal5050 for notification.

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Comments: 15 (13 by maintainers)

Most upvoted comments

@v-jiaodi Since this is using an external script you need to manually update it to include the following: $ErrorActionPreference='Stop'

This will instruct Powershell to stop on errors if this is the desired behavior. We will not be addressing this issue for external script hooks internally within azd for the time being.

What happens if we change the script to:

$ErrorActionPreference='Stop'; Write-Host1111 $env:AZURE_ENV_NAME?

Since ErrorActionPreference of powershell was likely set to Continue here, powershell will not stop on errors, and continue. The exit code would be 0. Setting $ErrorActionPreference='Stop' will appropriately terminate with non-zero exit code on errors.