d365collaborative / d365fo.tools

Tools used for Dynamics 365 Finance and Operations
MIT License
246 stars 102 forks source link

enableException not working for Invoke-D365AzCopyTransfer #842

Closed Simon-Syd closed 2 months ago

Simon-Syd commented 3 months ago

hello,

when using the Invoke-D365AzCopyTransfer command, Azure DevOps does not recognized the status of the job for example, if AzCopy return a "failed", "canceled" or other status, the PowerShell step will stop if you execut the exact same command with Invoke-D365AzCopyTransfer, it won't failed, even if we used the -EnableException parameters

so I don't know if it's possible to add this features please ? Or if it's not possible it's fine, I will switch back to AzCopy instead of Invoke-D365AzCopyTransfer because we have many problem with our releases due to the fact that the .bak file has not been downloaded and the release has continued

Simon

Splaxi commented 3 months ago

If you can play around with the Invoke-Process in powershell and see if AzCopy will honor true failure codes / exit codes - then we can implement that into the Invoke-D365AzCopyTransfer

Short term, without testing - we don't have any ideas or solutions. But with some assistance from you - we should be able to make something

FH-Inway commented 3 months ago

@Simon-Syd It should be possible to have the pipeline fail on the step with the Invoke-D365AzCopyTransfer command by using the $WarningPreference="Stop" option from our exception handling guide.

In the screenshot of the pipeline log you sent me via direct message, there is a line similar to the following that indicates d365fo.tools recognized that AzCopy failed.

[12:21:04][Invoke-Process] Exit code from AzCopy.exe indicated an error happened. Will output both standard stream and error stream.

There should also a line further down in the log that looks similar to this:

WARNING: [12:21:04][Invoke-Process] Stopping because of Exit Code. | Stopping because an Exit Code from AzCopy.exe wasn't 0 (zero) like expected.

That line/warning is the one that will fail the pipeline if the warning preference is set to "Stop". You can do that either inside the PowerShell script as mentioned in the exception handling guide or as a setting of the pipeline step.

Here is a screenshot of a pipeline I tested this with: image

Splaxi commented 2 months ago

@Simon-Syd

Did this unblock you? Please re-open the issue, if you need further assistance