-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fail on standard error option for azure powershell task (#6324)
* adding failonstderror option to azure ps task * updating the patch version to the correct number * moving failonstandarderror option to the advanced section * fix tests for redirecting errors * adding test to check that the task succeeds if failonstandarderror is set to false and non-terminating errors are written to the error stream * adding changes for erroractionpreference and failonstandarderror * minor changes * fixing tests * adding L0 test to check that failonstandarderror is honored * adding L0 test to check that failonstandarderror is honored * fix common tests * fix common tests * mitigate alias not found bug in latest azure powershell releases * use connect-azurermaccount cmdlet for usernamepassword authscheme as well * changing temp directory path from system temp directory to agent temp directory for generating inline script * update releasenotes and update comments
- Loading branch information
Showing
21 changed files
with
287 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
Tasks/AzurePowerShell/Tests/DoesNotFailOnStandardError.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
[CmdletBinding()] | ||
param() | ||
|
||
# Arrange. | ||
. $PSScriptRoot\..\..\..\Tests\lib\Initialize-Test.ps1 | ||
$targetAzurePs = "4.1.0" | ||
Register-Mock Get-VstsInput { "FilePath" } -- -Name ScriptType -Require | ||
Register-Mock Get-VstsInput { "$PSScriptRoot/RedirectsErrors_TargetScript.ps1" } -- -Name ScriptPath | ||
Register-Mock Get-VstsInput { $targetAzurePs } -- -Name TargetAzurePs | ||
Register-Mock Get-VstsInput { "continue" } -- -Name errorActionPreference | ||
Register-Mock Get-VstsInput { $false } -- -Name FailOnStandardError | ||
Register-Mock Update-PSModulePathForHostedAgent | ||
Register-Mock Initialize-Azure | ||
|
||
# Act. | ||
$actual = @( & $PSScriptRoot\..\AzurePowerShell.ps1 ) | ||
$global:ErrorActionPreference = 'Stop' # Reset to stop. | ||
|
||
# Assert. | ||
Assert-AreEqual 4 $actual.Length | ||
Assert-AreEqual 'Some output 1' $actual[0] | ||
Assert-AreEqual 'Some error 1' $actual[1].Exception.Message | ||
Assert-AreEqual 'Some output 2' $actual[2] | ||
Assert-AreEqual 'Some error 2' $actual[3].Exception.Message |
24 changes: 24 additions & 0 deletions
24
Tasks/AzurePowerShell/Tests/DoesNotThrowForNativeCommandError.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
[CmdletBinding()] | ||
param() | ||
|
||
# Arrange. | ||
. $PSScriptRoot\..\..\..\Tests\lib\Initialize-Test.ps1 | ||
$targetAzurePs = "4.1.0" | ||
Register-Mock Get-VstsInput { "FilePath" } -- -Name ScriptType -Require | ||
Register-Mock Get-VstsInput { "$PSScriptRoot/NativeCommandError_TargetScript.ps1" } -- -Name ScriptPath | ||
Register-Mock Get-VstsInput { $targetAzurePs } -- -Name TargetAzurePs | ||
Register-Mock Get-VstsInput { "stop" } -- -Name errorActionPreference | ||
Register-Mock Get-VstsInput { $false } -- -Name FailOnStandardError | ||
Register-Mock Update-PSModulePathForHostedAgent | ||
Register-Mock Initialize-Azure | ||
|
||
# Act. | ||
$actual = @( & $PSScriptRoot\..\AzurePowerShell.ps1 ) | ||
$global:ErrorActionPreference = 'Stop' # Reset to stop. | ||
|
||
# Assert. | ||
Assert-AreEqual 4 $actual.Length | ||
Assert-AreEqual 'output 1' $actual[0] | ||
Assert-AreEqual 'NativeCommandError' $actual[1].FullyQualifiedErrorId | ||
Assert-AreEqual 'NativeCommandErrorMessage' $actual[2].FullyQualifiedErrorId | ||
Assert-AreEqual 'output 2' $actual[3] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
Tasks/AzurePowerShell/Tests/FailsForNativeCommandError.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
[CmdletBinding()] | ||
param() | ||
|
||
# Arrange. | ||
. $PSScriptRoot\..\..\..\Tests\lib\Initialize-Test.ps1 | ||
$targetAzurePs = "4.1.0" | ||
Register-Mock Get-VstsInput { "FilePath" } -- -Name ScriptType -Require | ||
Register-Mock Get-VstsInput { "$PSScriptRoot/NativeCommandError_TargetScript.ps1" } -- -Name ScriptPath | ||
Register-Mock Get-VstsInput { $targetAzurePs } -- -Name TargetAzurePs | ||
Register-Mock Get-VstsInput { "silentlyContinue" } -- -Name errorActionPreference | ||
Register-Mock Get-VstsInput { $true } -- -Name FailOnStandardError | ||
Register-Mock Update-PSModulePathForHostedAgent | ||
Register-Mock Initialize-Azure | ||
|
||
# Act. | ||
$actual = @( & $PSScriptRoot\..\AzurePowerShell.ps1 ) | ||
$global:ErrorActionPreference = 'Stop' # Reset to stop. | ||
|
||
# Assert. | ||
Assert-AreEqual 6 $actual.Length | ||
Assert-AreEqual 'output 1' $actual[0] | ||
Assert-AreEqual 'NativeCommandError' $actual[1].FullyQualifiedErrorId | ||
Assert-AreEqual '##vso[task.complete result=Failed]' $actual[2] | ||
Assert-AreEqual 'NativeCommandErrorMessage' $actual[3].FullyQualifiedErrorId | ||
Assert-AreEqual '##vso[task.complete result=Failed]' $actual[4] | ||
Assert-AreEqual 'output 2' $actual[5] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
Tasks/AzurePowerShell/Tests/NativeCommandError_TargetScript.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Write-Output "output 1" | ||
net user foobar | ||
Write-Output "output 2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.