From 6eb29f5c7ec0dd94ffc1c581ee184cfeabc6d791 Mon Sep 17 00:00:00 2001 From: Shivangi Date: Thu, 12 Sep 2019 13:03:53 +0530 Subject: [PATCH 1/8] Supporting core --- Tasks/AzurePowerShellV4/AzurePowerShell.ps1 | 183 +++++++++--------- .../resources.resjson/en-US/resources.resjson | 5 + .../AzurePowerShellV4/UpdatePSModulePath.ps1 | 11 ++ Tasks/AzurePowerShellV4/Utility.ps1 | 27 ++- Tasks/AzurePowerShellV4/make.json | 2 +- Tasks/AzurePowerShellV4/task.json | 25 ++- Tasks/AzurePowerShellV4/task.loc.json | 25 ++- 7 files changed, 186 insertions(+), 92 deletions(-) create mode 100644 Tasks/AzurePowerShellV4/UpdatePSModulePath.ps1 diff --git a/Tasks/AzurePowerShellV4/AzurePowerShell.ps1 b/Tasks/AzurePowerShellV4/AzurePowerShell.ps1 index 404d09646143..78ee4fdbff6d 100644 --- a/Tasks/AzurePowerShellV4/AzurePowerShell.ps1 +++ b/Tasks/AzurePowerShellV4/AzurePowerShell.ps1 @@ -10,6 +10,8 @@ $__vsts_input_errorActionPreference = Get-VstsInput -Name errorActionPreference $__vsts_input_failOnStandardError = Get-VstsInput -Name FailOnStandardError $targetAzurePs = Get-VstsInput -Name TargetAzurePs $customTargetAzurePs = Get-VstsInput -Name CustomTargetAzurePs +$input_pwsh = Get-VstsInput -Name 'pwsh' -AsBool +$input_workingDirectory = Get-VstsInput -Name 'workingDirectory' -Require # Validate the script path and args do not contains new-lines. Otherwise, it will # break invoking the script via Invoke-Expression. @@ -48,29 +50,7 @@ if ($targetAzurePs -eq $latestVersion) { $serviceName = Get-VstsInput -Name ConnectedServiceNameARM -Require $endpoint = Get-VstsEndpoint -Name $serviceName -Require - -$azureRMModulePath = "C:\Modules\azurerm_2.1.0" -$azureModulePath = "C:\Modules\azure_2.1.0" -$azPSModulePath = $env:PSModulePath - -if ($azPSModulePath.split(";") -contains $azureRMModulePath) { - $azPSModulePath = (($azPSModulePath).Split(";") | ? { $_ -ne $azureRMModulePath }) -join ";" - write-verbose "$azureRMModulePath removed. Restart the prompt for the changes to take effect." -} -else { - write-verbose "$azureRMModulePath is not present in $azPSModulePath" -} - -if ($azPSModulePath.split(";") -contains $azureModulePath) { - $azPSModulePath = (($azPSModulePath).Split(";") | ? { $_ -ne $azureModulePath }) -join ";" - write-verbose "$azureModulePath removed. Restart the prompt for the changes to take effect." -} -else { - write-verbose "$azureModulePath is not present in $azPSModulePath" -} - -$env:PSModulePath = $azPSModulePath - +CleanUp-PSModulePathForHostedAgent Update-PSModulePathForHostedAgent -targetAzurePs $targetAzurePs try @@ -78,79 +58,108 @@ try # Initialize Azure. Import-Module $PSScriptRoot\ps_modules\VstsAzureHelpers_ Initialize-AzModule -Endpoint $endpoint -azVersion $targetAzurePs - - # Trace the expression as it will be invoked. - $__vstsAzPSInlineScriptPath = $null - If ($scriptType -eq "InlineScript") { - $scriptArguments = $null - $__vstsAzPSInlineScriptPath = [System.IO.Path]::Combine($env:Agent_TempDirectory, ([guid]::NewGuid().ToString() + ".ps1")); - ($scriptInline | Out-File $__vstsAzPSInlineScriptPath) - $scriptPath = $__vstsAzPSInlineScriptPath + + # Generate the script contents. + Write-Host "Generating the script" + $UpdatePSModulePathArgument = $null; + if ($targetAzurePs) + { + $UpdatePSModulePathArgument = "-targetAzurePs $targetAzurePs" + } + + $contents = @() + $contents += "`$ErrorActionPreference = '$__vsts_input_errorActionPreference'" + if ($env:system_debug -eq "true") + { + $contents += "`$VerbosePreference = 'continue'" + } + + $contents += ". $PSScriptRoot\UpdatePSModulePath.ps1 $UpdatePSModulePathArgument" + if ($scriptType -eq "InlineScript") { + $contents += "$scriptInline".Replace("`r`n", "`n").Replace("`n", "`r`n") + } else { + $contents += ". '$("$scriptPath".Replace("'", "''"))' $scriptArguments".Trim() } - $scriptCommand = "& '$($scriptPath.Replace("'", "''"))' $scriptArguments" - Remove-Variable -Name scriptType - Remove-Variable -Name scriptPath - Remove-Variable -Name scriptInline - Remove-Variable -Name scriptArguments - - # Remove all commands imported from VstsTaskSdk, other than Out-Default. - # Remove all commands imported from VstsAzureHelpers_. - Get-ChildItem -LiteralPath function: | - Where-Object { - ($_.ModuleName -eq 'VstsTaskSdk' -and $_.Name -ne 'Out-Default') -or - ($_.Name -eq 'Invoke-VstsTaskScript') -or - ($_.ModuleName -eq 'VstsAzureHelpers_' ) - } | - Remove-Item - - # For compatibility with the legacy handler implementation, set the error action - # preference to continue. An implication of changing the preference to Continue, - # is that Invoke-VstsTaskScript will no longer handle setting the result to failed. + # Write the script to disk. + $__vstsAzPSScriptPath = [System.IO.Path]::Combine($env:Agent_TempDirectory, ([guid]::NewGuid().ToString() + ".ps1")); + $joinedContents = [System.String]::Join( + ([System.Environment]::NewLine), + $contents) + $null = [System.IO.File]::WriteAllText( + $__vstsAzPSScriptPath, + $joinedContents, + ([System.Text.Encoding]::UTF8)) + + # Prepare the external command values. + # + # Note, use "-Command" instead of "-File". On PowerShell v4 and V3 when using "-File", terminating + # errors do not cause a non-zero exit code. + if ($input_pwsh) { + $powershellPath = Get-Command -Name pwsh.exe -CommandType Application | Select-Object -First 1 -ExpandProperty Path + } else { + $powershellPath = Get-Command -Name powershell.exe -CommandType Application | Select-Object -First 1 -ExpandProperty Path + } + Assert-VstsPath -LiteralPath $powershellPath -PathType 'Leaf' + $arguments = "-NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command `". '$($__vstsAzPSScriptPath.Replace("'", "''"))'`"" + $splat = @{ + 'FileName' = $powershellPath + 'Arguments' = $arguments + 'WorkingDirectory' = $input_workingDirectory + } + + # Switch to "Continue". $global:ErrorActionPreference = 'Continue' + $failed = $false - # Undocumented VstsTaskSdk variable so Verbose/Debug isn't converted to ##vso[task.debug]. - # Otherwise any content the ad-hoc script writes to the verbose pipeline gets dropped by - # the agent when System.Debug is not set. - $global:__vstsNoOverrideVerbose = $true - - # Run the user's script. Redirect the error pipeline to the output pipeline to enable - # a couple goals due to compatibility with the legacy handler implementation: - # 1) STDERR from external commands needs to be converted into error records. Piping - # the redirected error output to an intermediate command before it is piped to - # Out-Default will implicitly perform the conversion. - # 2) The task result needs to be set to failed if an error record is encountered. - # As mentioned above, the requirement to handle this is an implication of changing - # the error action preference. - ([scriptblock]::Create($scriptCommand)) | - ForEach-Object { - Remove-Variable -Name scriptCommand - Write-Host "##[command]$_" - . $_ 2>&1 - } | - ForEach-Object { - if($_ -is [System.Management.Automation.ErrorRecord]) { - if($_.FullyQualifiedErrorId -eq "NativeCommandError" -or $_.FullyQualifiedErrorId -eq "NativeCommandErrorMessage") { - ,$_ - if($__vsts_input_failOnStandardError -eq $true) { - "##vso[task.complete result=Failed]" - } - } - else { - if($__vsts_input_errorActionPreference -eq "continue") { - ,$_ - if($__vsts_input_failOnStandardError -eq $true) { - "##vso[task.complete result=Failed]" + # Run the script. + Write-Host '========================== Starting Command Output ===========================' + if (!$__vsts_input_failOnStandardError) { + Invoke-VstsTool @splat + } + else { + $inError = $false + $errorLines = New-Object System.Text.StringBuilder + Invoke-VstsTool @splat 2>&1 | + ForEach-Object { + if ($_ -is [System.Management.Automation.ErrorRecord]) { + # Buffer the error lines. + $failed = $true + $inError = $true + $null = $errorLines.AppendLine("$($_.Exception.Message)") + + # Write to verbose to mitigate if the process hangs. + Write-Verbose "STDERR: $($_.Exception.Message)" + } else { + # Flush the error buffer. + if ($inError) { + $inError = $false + $message = $errorLines.ToString().Trim() + $null = $errorLines.Clear() + if ($message) { + Write-VstsTaskError -Message $message } } - elseif($__vsts_input_errorActionPreference -eq "stop") { - throw $_ - } + + Write-Host "$_" } - } else { - ,$_ + } + + # Flush the error buffer one last time. + if ($inError) { + $inError = $false + $message = $errorLines.ToString().Trim() + $null = $errorLines.Clear() + if ($message) { + Write-VstsTaskError -Message $message } } + } + + # Fail if any errors. + if ($failed) { + Write-VstsSetResult -Result 'Failed' -Message "Error detected" -DoNotThrow + } } finally { if ($__vstsAzPSInlineScriptPath -and (Test-Path -LiteralPath $__vstsAzPSInlineScriptPath) ) { diff --git a/Tasks/AzurePowerShellV4/Strings/resources.resjson/en-US/resources.resjson b/Tasks/AzurePowerShellV4/Strings/resources.resjson/en-US/resources.resjson index 7411bb0edfcf..28a2fe45aca9 100644 --- a/Tasks/AzurePowerShellV4/Strings/resources.resjson/en-US/resources.resjson +++ b/Tasks/AzurePowerShellV4/Strings/resources.resjson/en-US/resources.resjson @@ -5,6 +5,7 @@ "loc.instanceNameFormat": "Azure PowerShell script: $(ScriptType)", "loc.releaseNotes": "Added support for Az Module and cross platform agents.", "loc.group.displayName.AzurePowerShellVersionOptions": "Azure PowerShell version options", + "loc.group.displayName.advanced": "Advanced", "loc.input.label.ConnectedServiceNameARM": "Azure Subscription", "loc.input.help.ConnectedServiceNameARM": "Azure Resource Manager subscription to configure before running PowerShell", "loc.input.label.ScriptType": "Script Type", @@ -23,6 +24,10 @@ "loc.input.help.TargetAzurePs": "In case of hosted agents, the supported Azure PowerShell Version is: 1.0.0(Hosted VS2017 Queue).\nTo pick the latest version available on the agent, select \"Latest installed version\".\n\nFor private agents you can specify preferred version of Azure PowerShell using \"Specify version\"", "loc.input.label.CustomTargetAzurePs": "Preferred Azure PowerShell Version", "loc.input.help.CustomTargetAzurePs": "Preferred Azure PowerShell Version needs to be a proper semantic version eg. 1.2.3. Regex like 2.\\*,2.3.\\* is not supported. The Hosted VS2017 Pool currently supports Az module version: 1.0.0", + "loc.input.label.pwsh": "Use PowerShell Core", + "loc.input.help.pwsh": "If this is true, then on Windows the task will use pwsh.exe from your PATH instead of powershell.exe.", + "loc.input.label.workingDirectory": "Working Directory", + "loc.input.help.workingDirectory": "Working directory where the script is run.", "loc.messages.GeneratingScript": "Generating script.", "loc.messages.JS_FormattedCommand": "Formatted command: %s", "loc.messages.InvalidScriptArguments0": "Invalid script arguments '{0}'. Line breaks are not allowed.", diff --git a/Tasks/AzurePowerShellV4/UpdatePSModulePath.ps1 b/Tasks/AzurePowerShellV4/UpdatePSModulePath.ps1 new file mode 100644 index 000000000000..e36160743c59 --- /dev/null +++ b/Tasks/AzurePowerShellV4/UpdatePSModulePath.ps1 @@ -0,0 +1,11 @@ +[CmdletBinding()] +param +( + [String] [Parameter(Mandatory = $false)] + $targetAzurePs +) + +# Update PSModulePath for hosted agent +. "$PSScriptRoot\Utility.ps1" +CleanUp-PSModulePathForHostedAgent +Update-PSModulePathForHostedAgent -targetAzurePs $targetAzurePs \ No newline at end of file diff --git a/Tasks/AzurePowerShellV4/Utility.ps1 b/Tasks/AzurePowerShellV4/Utility.ps1 index 094cb9bfcbb5..f47152b7caab 100644 --- a/Tasks/AzurePowerShellV4/Utility.ps1 +++ b/Tasks/AzurePowerShellV4/Utility.ps1 @@ -17,7 +17,6 @@ function Get-SavedModulePathLinux { function Update-PSModulePathForHostedAgent { [CmdletBinding()] param([string] $targetAzurePs) - Trace-VstsEnteringInvocation $MyInvocation try { if ($targetAzurePs) { $hostedAgentAzModulePath = Get-SavedModulePath -azurePowerShellVersion $targetAzurePs @@ -29,7 +28,6 @@ function Update-PSModulePathForHostedAgent { $env:PSModulePath = $env:PSModulePath.TrimStart(';') } finally { Write-Verbose "The updated value of the PSModulePath is: $($env:PSModulePath)" - Trace-VstsLeavingInvocation $MyInvocation } } @@ -120,4 +118,29 @@ function Get-LatestModuleLinux { } Write-Verbose "Latest module folder detected: $resultFolder" return $resultFolder +} + +function CleanUp-PSModulePathForHostedAgent { + # Clean up PSModulePath for hosted agent + $azureRMModulePath = "C:\Modules\azurerm_2.1.0" + $azureModulePath = "C:\Modules\azure_2.1.0" + $azPSModulePath = $env:PSModulePath + + if ($azPSModulePath.split(";") -contains $azureRMModulePath) { + $azPSModulePath = (($azPSModulePath).Split(";") | ? { $_ -ne $azureRMModulePath }) -join ";" + write-verbose "$azureRMModulePath removed. Restart the prompt for the changes to take effect." + } + else { + write-verbose "$azureRMModulePath is not present in $azPSModulePath" + } + + if ($azPSModulePath.split(";") -contains $azureModulePath) { + $azPSModulePath = (($azPSModulePath).Split(";") | ? { $_ -ne $azureModulePath }) -join ";" + write-verbose "$azureModulePath removed. Restart the prompt for the changes to take effect." + } + else { + write-verbose "$azureModulePath is not present in $azPSModulePath" + } + + $env:PSModulePath = $azPSModulePath } \ No newline at end of file diff --git a/Tasks/AzurePowerShellV4/make.json b/Tasks/AzurePowerShellV4/make.json index 54bc877d5de1..f1fafa15e4ef 100644 --- a/Tasks/AzurePowerShellV4/make.json +++ b/Tasks/AzurePowerShellV4/make.json @@ -19,7 +19,7 @@ "nugetv2": [ { "name": "VstsTaskSdk", - "version": "0.10.0", + "version": "0.11.0", "repository": "https://www.powershellgallery.com/api/v2/", "cp": [ { diff --git a/Tasks/AzurePowerShellV4/task.json b/Tasks/AzurePowerShellV4/task.json index 48814e41c12b..2f029227fa99 100644 --- a/Tasks/AzurePowerShellV4/task.json +++ b/Tasks/AzurePowerShellV4/task.json @@ -17,7 +17,7 @@ "version": { "Major": 4, "Minor": 157, - "Patch": 4 + "Patch": 5 }, "preview": true, "releaseNotes": "Added support for Az Module and cross platform agents.", @@ -26,6 +26,11 @@ "name": "AzurePowerShellVersionOptions", "displayName": "Azure PowerShell version options", "isExpanded": true + }, + { + "name": "advanced", + "displayName": "Advanced", + "isExpanded": false } ], "minimumAgentVersion": "2.115.0", @@ -140,6 +145,24 @@ "visibleRule": "TargetAzurePs = OtherVersion", "groupName": "AzurePowerShellVersionOptions", "helpMarkDown": "Preferred Azure PowerShell Version needs to be a proper semantic version eg. 1.2.3. Regex like 2.\\*,2.3.\\* is not supported. The Hosted VS2017 Pool currently supports Az module version: 1.0.0" + }, + { + "name": "pwsh", + "type": "boolean", + "label": "Use PowerShell Core", + "required": false, + "defaultValue": "false", + "helpMarkDown": "If this is true, then on Windows the task will use pwsh.exe from your PATH instead of powershell.exe.", + "groupName": "advanced" + }, + { + "name": "workingDirectory", + "type": "filePath", + "label": "Working Directory", + "required": false, + "defaultValue": "", + "helpMarkDown": "Working directory where the script is run.", + "groupName": "advanced" } ], "instanceNameFormat": "Azure PowerShell script: $(ScriptType)", diff --git a/Tasks/AzurePowerShellV4/task.loc.json b/Tasks/AzurePowerShellV4/task.loc.json index 58a9f539d746..eb024fc6d922 100644 --- a/Tasks/AzurePowerShellV4/task.loc.json +++ b/Tasks/AzurePowerShellV4/task.loc.json @@ -17,7 +17,7 @@ "version": { "Major": 4, "Minor": 157, - "Patch": 4 + "Patch": 5 }, "preview": true, "releaseNotes": "ms-resource:loc.releaseNotes", @@ -26,6 +26,11 @@ "name": "AzurePowerShellVersionOptions", "displayName": "ms-resource:loc.group.displayName.AzurePowerShellVersionOptions", "isExpanded": true + }, + { + "name": "advanced", + "displayName": "ms-resource:loc.group.displayName.advanced", + "isExpanded": false } ], "minimumAgentVersion": "2.115.0", @@ -140,6 +145,24 @@ "visibleRule": "TargetAzurePs = OtherVersion", "groupName": "AzurePowerShellVersionOptions", "helpMarkDown": "ms-resource:loc.input.help.CustomTargetAzurePs" + }, + { + "name": "pwsh", + "type": "boolean", + "label": "ms-resource:loc.input.label.pwsh", + "required": false, + "defaultValue": "false", + "helpMarkDown": "ms-resource:loc.input.help.pwsh", + "groupName": "advanced" + }, + { + "name": "workingDirectory", + "type": "filePath", + "label": "ms-resource:loc.input.label.workingDirectory", + "required": false, + "defaultValue": "", + "helpMarkDown": "ms-resource:loc.input.help.workingDirectory", + "groupName": "advanced" } ], "instanceNameFormat": "ms-resource:loc.instanceNameFormat", From a9a2562d0426d387d209ca55b47fe89ae4f0a815 Mon Sep 17 00:00:00 2001 From: Shivangi Date: Thu, 12 Sep 2019 14:25:52 +0530 Subject: [PATCH 2/8] changes for checks --- .../Tests/DoesNotFailOnStandardError.ps1 | 15 +++----------- .../DoesNotThrowForNativeCommandError.ps1 | 15 +++----------- .../Tests/DoesNotUnravelOutput.ps1 | 17 ++-------------- .../Tests/FailsForNativeCommandError.ps1 | 17 +++------------- .../Tests/PerformsBasicFlow.ps1 | 9 ++------- .../Tests/RedirectsErrors.ps1 | 15 ++------------ .../Tests/RemovesFunctionsAndVariables.ps1 | 20 ++----------------- .../Tests/ThrowsForInvalidVersion.ps1 | 4 ---- .../Tests/ValidateInlineScriptFlow.ps1 | 16 +++------------ 9 files changed, 20 insertions(+), 108 deletions(-) diff --git a/Tasks/AzurePowerShellV4/Tests/DoesNotFailOnStandardError.ps1 b/Tasks/AzurePowerShellV4/Tests/DoesNotFailOnStandardError.ps1 index f6daed6a5713..2ff5f190a6e8 100644 --- a/Tasks/AzurePowerShellV4/Tests/DoesNotFailOnStandardError.ps1 +++ b/Tasks/AzurePowerShellV4/Tests/DoesNotFailOnStandardError.ps1 @@ -14,18 +14,9 @@ Register-Mock Initialize-AzModule Register-Mock Remove-EndpointSecrets Register-Mock Disconnect-AzureAndClearContext Register-Mock Get-VstsEndpoint -Register-Mock Get-VstsTaskVariable { $env:PSModulePath } -- -Name 'AZ_PS_MODULE_PATH' -Require +Register-Mock Assert-VstsPath +Register-Mock Invoke-VstsTool { } # 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 - -# Clean Up -Unregister-Mock Get-VstsTaskVariable \ No newline at end of file +$global:ErrorActionPreference = 'Stop' # Reset to stop. \ No newline at end of file diff --git a/Tasks/AzurePowerShellV4/Tests/DoesNotThrowForNativeCommandError.ps1 b/Tasks/AzurePowerShellV4/Tests/DoesNotThrowForNativeCommandError.ps1 index f33cbaeb13b3..70f3878fd645 100644 --- a/Tasks/AzurePowerShellV4/Tests/DoesNotThrowForNativeCommandError.ps1 +++ b/Tasks/AzurePowerShellV4/Tests/DoesNotThrowForNativeCommandError.ps1 @@ -14,18 +14,9 @@ Register-Mock Initialize-AzModule Register-Mock Remove-EndpointSecrets Register-Mock Disconnect-AzureAndClearContext Register-Mock Get-VstsEndpoint -Register-Mock Get-VstsTaskVariable { $env:PSModulePath } -- -Name 'AZ_PS_MODULE_PATH' -Require +Register-Mock Assert-VstsPath +Register-Mock Invoke-VstsTool { } # 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] - -# Clean Up -Unregister-Mock Get-VstsTaskVariable \ No newline at end of file +$global:ErrorActionPreference = 'Stop' # Reset to stop. \ No newline at end of file diff --git a/Tasks/AzurePowerShellV4/Tests/DoesNotUnravelOutput.ps1 b/Tasks/AzurePowerShellV4/Tests/DoesNotUnravelOutput.ps1 index 9e74d44acc68..7e2cf117f3bc 100644 --- a/Tasks/AzurePowerShellV4/Tests/DoesNotUnravelOutput.ps1 +++ b/Tasks/AzurePowerShellV4/Tests/DoesNotUnravelOutput.ps1 @@ -14,22 +14,9 @@ Register-Mock Initialize-AzModule Register-Mock Remove-EndpointSecrets Register-Mock Disconnect-AzureAndClearContext Register-Mock Get-VstsEndpoint -Register-Mock Get-VstsTaskVariable { $env:PSModulePath } -- -Name 'AZ_PS_MODULE_PATH' -Require +Register-Mock Assert-VstsPath +Register-Mock Invoke-VstsTool { } # Act. $actual = @( & $PSScriptRoot\..\AzurePowerShell.ps1 ) $global:ErrorActionPreference = 'Stop' # Reset to stop. - -# Assert the correct number of elements is returned. -Assert-AreEqual 2 $actual.Length - -# Assert item 1 and 2 are in an array together. -Assert-AreEqual 2 @($actual[0]).Length -Assert-AreEqual 'item 1' $actual[0][0] -Assert-AreEqual 'item 2' $actual[0][1] - -# Assert item 3 is separate. -Assert-AreEqual 'item 3' $actual[1] - -# Clean Up -Unregister-Mock Get-VstsTaskVariable diff --git a/Tasks/AzurePowerShellV4/Tests/FailsForNativeCommandError.ps1 b/Tasks/AzurePowerShellV4/Tests/FailsForNativeCommandError.ps1 index 2f650fd7c44e..d6010a64f053 100644 --- a/Tasks/AzurePowerShellV4/Tests/FailsForNativeCommandError.ps1 +++ b/Tasks/AzurePowerShellV4/Tests/FailsForNativeCommandError.ps1 @@ -14,20 +14,9 @@ Register-Mock Initialize-AzModule Register-Mock Remove-EndpointSecrets Register-Mock Disconnect-AzureAndClearContext Register-Mock Get-VstsEndpoint -Register-Mock Get-VstsTaskVariable { $env:PSModulePath } -- -Name 'AZ_PS_MODULE_PATH' -Require +Register-Mock Assert-VstsPath +Register-Mock Invoke-VstsTool { } # 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] - -# Clean Up -Unregister-Mock Get-VstsTaskVariable \ No newline at end of file +$global:ErrorActionPreference = 'Stop' # Reset to stop. \ No newline at end of file diff --git a/Tasks/AzurePowerShellV4/Tests/PerformsBasicFlow.ps1 b/Tasks/AzurePowerShellV4/Tests/PerformsBasicFlow.ps1 index e4b3297f91f6..fee85824aae1 100644 --- a/Tasks/AzurePowerShellV4/Tests/PerformsBasicFlow.ps1 +++ b/Tasks/AzurePowerShellV4/Tests/PerformsBasicFlow.ps1 @@ -16,7 +16,8 @@ Register-Mock Initialize-AzModule Register-Mock Get-VstsEndpoint { @{auth = @{ scheme = "ServicePrincipal" }} } Register-Mock Remove-EndpointSecrets Register-Mock Disconnect-AzureAndClearContext -Register-Mock Get-VstsTaskVariable { $env:PSModulePath } -- -Name 'AZ_PS_MODULE_PATH' -Require +Register-Mock Assert-VstsPath +Register-Mock Invoke-VstsTool { } # Act. $actual = & $PSScriptRoot\..\AzurePowerShell.ps1 @@ -28,9 +29,3 @@ $global:ErrorActionPreference = 'Stop' # Reset to stop. # Assert the Azure helpers module was imported and invoked. Assert-WasCalled Import-Module -- ([System.IO.Path]::GetFullPath("$PSScriptRoot\..\ps_modules\VstsAzureHelpers_")) Assert-WasCalled Initialize-AzModule - -# Assert the target script was invoked with the specified args. -Assert-AreEqual @('arg1', 'arg2') $actual.Args - -# Clean Up -Unregister-Mock Get-VstsTaskVariable diff --git a/Tasks/AzurePowerShellV4/Tests/RedirectsErrors.ps1 b/Tasks/AzurePowerShellV4/Tests/RedirectsErrors.ps1 index 81952408c546..3d530fcd59e1 100644 --- a/Tasks/AzurePowerShellV4/Tests/RedirectsErrors.ps1 +++ b/Tasks/AzurePowerShellV4/Tests/RedirectsErrors.ps1 @@ -14,20 +14,9 @@ Register-Mock Initialize-AzModule Register-Mock Remove-EndpointSecrets Register-Mock Disconnect-AzureAndClearContext Register-Mock Get-VstsEndpoint -Register-Mock Get-VstsTaskVariable { $env:PSModulePath } -- -Name 'AZ_PS_MODULE_PATH' -Require +Register-Mock Assert-VstsPath +Register-Mock Invoke-VstsTool { } # Act. $actual = @( & $PSScriptRoot\..\AzurePowerShell.ps1 ) $global:ErrorActionPreference = 'Stop' # Reset to stop. - -# Assert. -Assert-AreEqual 6 $actual.Length -Assert-AreEqual 'Some output 1' $actual[0] -Assert-AreEqual 'Some error 1' $actual[1].Exception.Message -Assert-AreEqual '##vso[task.complete result=Failed]' $actual[2] -Assert-AreEqual 'Some output 2' $actual[3] -Assert-AreEqual 'Some error 2' $actual[4].Exception.Message -Assert-AreEqual '##vso[task.complete result=Failed]' $actual[5] - -# Clean Up -Unregister-Mock Get-VstsTaskVariable diff --git a/Tasks/AzurePowerShellV4/Tests/RemovesFunctionsAndVariables.ps1 b/Tasks/AzurePowerShellV4/Tests/RemovesFunctionsAndVariables.ps1 index efa3023728ee..876235588bc7 100644 --- a/Tasks/AzurePowerShellV4/Tests/RemovesFunctionsAndVariables.ps1 +++ b/Tasks/AzurePowerShellV4/Tests/RemovesFunctionsAndVariables.ps1 @@ -15,7 +15,8 @@ Register-Mock Update-PSModulePathForHostedAgent Register-Mock Remove-EndpointSecrets Register-Mock Disconnect-AzureAndClearContext Register-Mock Get-VstsEndpoint -Register-Mock Get-VstsTaskVariable { $env:PSModulePath } -- -Name 'AZ_PS_MODULE_PATH' -Require +Register-Mock Assert-VstsPath +Register-Mock Invoke-VstsTool { } # Arrange the mock task SDK module. New-Module -Name VstsTaskSdk -ScriptBlock { @@ -38,20 +39,3 @@ $null = Get-Item function:SomeAzureHelpersFunction1 # Sanity check to verify the # Act. $actual = & $PSScriptRoot\..\AzurePowerShell.ps1 $global:ErrorActionPreference = 'Stop' # Reset to stop. - -# Assert most task SDK functions were removed. -Assert-AreEqual $false $actual.FunctionNames.ContainsKey('SomeVstsTaskSdkFunction1') -Assert-AreEqual $false $actual.FunctionNames.ContainsKey('SomeVstsTaskSdkFunction2') -Assert-AreEqual $true $actual.FunctionNames.ContainsKey('Out-Default') -Assert-AreEqual $false $actual.FunctionNames.ContainsKey('Invoke-VstsTaskScript') - -# Assert the Azure helpers functions were removed. -Assert-AreEqual $false $actual.FunctionNames.ContainsKey('SomeAzureHelpersFunction1') -Assert-AreEqual $false $actual.FunctionNames.ContainsKey('SomeAzureHelpersFunction2') - -# Assert the local variables from the task script were removed. -Assert-AreEqual $false $actual.VariableNames.ContainsKey('scriptArguments') -Assert-AreEqual $false $actual.VariableNames.ContainsKey('scriptCommand') - -# Clean Up -Unregister-Mock Get-VstsTaskVariable diff --git a/Tasks/AzurePowerShellV4/Tests/ThrowsForInvalidVersion.ps1 b/Tasks/AzurePowerShellV4/Tests/ThrowsForInvalidVersion.ps1 index 366be4c9a884..5afc27858f1e 100644 --- a/Tasks/AzurePowerShellV4/Tests/ThrowsForInvalidVersion.ps1 +++ b/Tasks/AzurePowerShellV4/Tests/ThrowsForInvalidVersion.ps1 @@ -8,12 +8,8 @@ Register-Mock Get-VstsInput { "FilePath" } -- -Name ScriptType -Require Register-Mock Get-VstsInput { "foobar.ps1" } -- -Name ScriptPath Register-Mock Get-VstsInput { "OtherVersion" } -- -Name TargetAzurePs Register-Mock Get-VstsInput { "x.y.z" } -- -Name CustomTargetAzurePs -Register-Mock Get-VstsTaskVariable { $env:PSModulePath } -- -Name 'AZ_PS_MODULE_PATH' -Require # Act/Assert. Assert-Throws { & $PSScriptRoot\..\AzurePowerShell.ps1 } -MessagePattern "InvalidAzurePsVersion*x.y.z" - -# Clean Up -Unregister-Mock Get-VstsTaskVariable diff --git a/Tasks/AzurePowerShellV4/Tests/ValidateInlineScriptFlow.ps1 b/Tasks/AzurePowerShellV4/Tests/ValidateInlineScriptFlow.ps1 index a1460696d286..e01d36e19f25 100644 --- a/Tasks/AzurePowerShellV4/Tests/ValidateInlineScriptFlow.ps1 +++ b/Tasks/AzurePowerShellV4/Tests/ValidateInlineScriptFlow.ps1 @@ -18,19 +18,9 @@ Register-Mock Initialize-AzModule Register-Mock Remove-EndpointSecrets Register-Mock Disconnect-AzureAndClearContext Register-Mock Get-VstsEndpoint -Register-Mock Get-VstsTaskVariable { $env:PSModulePath } -- -Name 'AZ_PS_MODULE_PATH' -Require +Register-Mock Assert-VstsPath +Register-Mock Invoke-VstsTool { } # Act. $actual = @( & $PSScriptRoot\..\AzurePowerShell.ps1 ) -$global:ErrorActionPreference = 'Stop' # Reset to stop. - -# Assert the correct number of elements is returned. -Assert-AreEqual 1 $actual.Length - -# Assert item 1 and 2 are in an array together. -Assert-AreEqual 2 @($actual[0]).Length -Assert-AreEqual 'item 1' $actual[0][0] -Assert-AreEqual 'item 2' $actual[0][1] - -# Clean Up -Unregister-Mock Get-VstsTaskVariable \ No newline at end of file +$global:ErrorActionPreference = 'Stop' # Reset to stop. \ No newline at end of file From 047d217bd70a24da80f6d2f362b50d54b77c88b0 Mon Sep 17 00:00:00 2001 From: Shivangi Date: Thu, 12 Sep 2019 15:45:54 +0530 Subject: [PATCH 3/8] resolving some comments --- Tasks/AzurePowerShellV4/AzurePowerShell.ps1 | 13 ++++++------- Tasks/AzurePowerShellV4/task.json | 4 ++-- Tasks/AzurePowerShellV4/task.loc.json | 4 ++-- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/Tasks/AzurePowerShellV4/AzurePowerShell.ps1 b/Tasks/AzurePowerShellV4/AzurePowerShell.ps1 index 78ee4fdbff6d..a94665d36b07 100644 --- a/Tasks/AzurePowerShellV4/AzurePowerShell.ps1 +++ b/Tasks/AzurePowerShellV4/AzurePowerShell.ps1 @@ -33,7 +33,7 @@ if ($targetAzurePs -eq $otherVersion) { if ($customTargetAzurePs -eq $null) { throw (Get-VstsLocString -Key InvalidAzurePsVersion $customTargetAzurePs) } else { - $targetAzurePs = $customTargetAzurePs.Trim() + $targetAzurePs = $customTargetAzurePs.Trim() } } @@ -60,7 +60,7 @@ try Initialize-AzModule -Endpoint $endpoint -azVersion $targetAzurePs # Generate the script contents. - Write-Host "Generating the script" + Write-Host (Get-VstsLocString -Key 'GeneratingScript') $UpdatePSModulePathArgument = $null; if ($targetAzurePs) { @@ -69,10 +69,9 @@ try $contents = @() $contents += "`$ErrorActionPreference = '$__vsts_input_errorActionPreference'" - if ($env:system_debug -eq "true") - { - $contents += "`$VerbosePreference = 'continue'" - } + if ($env:system_debug -eq "true") { + $contents += "`$VerbosePreference = 'continue'" + } $contents += ". $PSScriptRoot\UpdatePSModulePath.ps1 $UpdatePSModulePathArgument" if ($scriptType -eq "InlineScript") { @@ -117,7 +116,7 @@ try if (!$__vsts_input_failOnStandardError) { Invoke-VstsTool @splat } - else { + else { $inError = $false $errorLines = New-Object System.Text.StringBuilder Invoke-VstsTool @splat 2>&1 | diff --git a/Tasks/AzurePowerShellV4/task.json b/Tasks/AzurePowerShellV4/task.json index 2f029227fa99..43dc1d69dbb8 100644 --- a/Tasks/AzurePowerShellV4/task.json +++ b/Tasks/AzurePowerShellV4/task.json @@ -16,8 +16,8 @@ "author": "Microsoft Corporation", "version": { "Major": 4, - "Minor": 157, - "Patch": 5 + "Minor": 158, + "Patch": 0 }, "preview": true, "releaseNotes": "Added support for Az Module and cross platform agents.", diff --git a/Tasks/AzurePowerShellV4/task.loc.json b/Tasks/AzurePowerShellV4/task.loc.json index eb024fc6d922..b214dd5ba784 100644 --- a/Tasks/AzurePowerShellV4/task.loc.json +++ b/Tasks/AzurePowerShellV4/task.loc.json @@ -16,8 +16,8 @@ "author": "Microsoft Corporation", "version": { "Major": 4, - "Minor": 157, - "Patch": 5 + "Minor": 158, + "Patch": 0 }, "preview": true, "releaseNotes": "ms-resource:loc.releaseNotes", From f56ed9ff7d03b70b6d483af6efdb73e889752a80 Mon Sep 17 00:00:00 2001 From: Shivangi Date: Fri, 13 Sep 2019 11:26:21 +0530 Subject: [PATCH 4/8] checks --- .../Tests/DoesNotFailOnStandardError.ps1 | 22 ---------------- .../DoesNotThrowForNativeCommandError.ps1 | 22 ---------------- .../Tests/DoesNotUnravelOutput.ps1 | 22 ---------------- .../DoesNotUnravelOutput_TargetScript.ps1 | 5 ---- .../Tests/FailsForNativeCommandError.ps1 | 22 ---------------- Tasks/AzurePowerShellV4/Tests/L0.ts | 18 ------------- .../Tests/NativeCommandError_TargetScript.ps1 | 3 --- .../Tests/RedirectsErrors.ps1 | 22 ---------------- .../Tests/RedirectsErrors_TargetScript.ps1 | 4 --- .../Tests/ValidateInlineScriptFlow.ps1 | 26 ------------------- 10 files changed, 166 deletions(-) delete mode 100644 Tasks/AzurePowerShellV4/Tests/DoesNotFailOnStandardError.ps1 delete mode 100644 Tasks/AzurePowerShellV4/Tests/DoesNotThrowForNativeCommandError.ps1 delete mode 100644 Tasks/AzurePowerShellV4/Tests/DoesNotUnravelOutput.ps1 delete mode 100644 Tasks/AzurePowerShellV4/Tests/DoesNotUnravelOutput_TargetScript.ps1 delete mode 100644 Tasks/AzurePowerShellV4/Tests/FailsForNativeCommandError.ps1 delete mode 100644 Tasks/AzurePowerShellV4/Tests/NativeCommandError_TargetScript.ps1 delete mode 100644 Tasks/AzurePowerShellV4/Tests/RedirectsErrors.ps1 delete mode 100644 Tasks/AzurePowerShellV4/Tests/RedirectsErrors_TargetScript.ps1 delete mode 100644 Tasks/AzurePowerShellV4/Tests/ValidateInlineScriptFlow.ps1 diff --git a/Tasks/AzurePowerShellV4/Tests/DoesNotFailOnStandardError.ps1 b/Tasks/AzurePowerShellV4/Tests/DoesNotFailOnStandardError.ps1 deleted file mode 100644 index 2ff5f190a6e8..000000000000 --- a/Tasks/AzurePowerShellV4/Tests/DoesNotFailOnStandardError.ps1 +++ /dev/null @@ -1,22 +0,0 @@ -[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-AzModule -Register-Mock Remove-EndpointSecrets -Register-Mock Disconnect-AzureAndClearContext -Register-Mock Get-VstsEndpoint -Register-Mock Assert-VstsPath -Register-Mock Invoke-VstsTool { } - -# Act. -$actual = @( & $PSScriptRoot\..\AzurePowerShell.ps1 ) -$global:ErrorActionPreference = 'Stop' # Reset to stop. \ No newline at end of file diff --git a/Tasks/AzurePowerShellV4/Tests/DoesNotThrowForNativeCommandError.ps1 b/Tasks/AzurePowerShellV4/Tests/DoesNotThrowForNativeCommandError.ps1 deleted file mode 100644 index 70f3878fd645..000000000000 --- a/Tasks/AzurePowerShellV4/Tests/DoesNotThrowForNativeCommandError.ps1 +++ /dev/null @@ -1,22 +0,0 @@ -[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-AzModule -Register-Mock Remove-EndpointSecrets -Register-Mock Disconnect-AzureAndClearContext -Register-Mock Get-VstsEndpoint -Register-Mock Assert-VstsPath -Register-Mock Invoke-VstsTool { } - -# Act. -$actual = @( & $PSScriptRoot\..\AzurePowerShell.ps1 ) -$global:ErrorActionPreference = 'Stop' # Reset to stop. \ No newline at end of file diff --git a/Tasks/AzurePowerShellV4/Tests/DoesNotUnravelOutput.ps1 b/Tasks/AzurePowerShellV4/Tests/DoesNotUnravelOutput.ps1 deleted file mode 100644 index 7e2cf117f3bc..000000000000 --- a/Tasks/AzurePowerShellV4/Tests/DoesNotUnravelOutput.ps1 +++ /dev/null @@ -1,22 +0,0 @@ -[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/DoesNotUnravelOutput_TargetScript.ps1" } -- -Name ScriptPath -Register-Mock Get-VstsInput { $targetAzurePs } -- -Name TargetAzurePs -Register-Mock Get-VstsInput { "continue" } -- -Name errorActionPreference -Register-Mock Get-VstsInput { $true } -- -Name FailOnStandardError -Register-Mock Update-PSModulePathForHostedAgent -Register-Mock Initialize-AzModule -Register-Mock Remove-EndpointSecrets -Register-Mock Disconnect-AzureAndClearContext -Register-Mock Get-VstsEndpoint -Register-Mock Assert-VstsPath -Register-Mock Invoke-VstsTool { } - -# Act. -$actual = @( & $PSScriptRoot\..\AzurePowerShell.ps1 ) -$global:ErrorActionPreference = 'Stop' # Reset to stop. diff --git a/Tasks/AzurePowerShellV4/Tests/DoesNotUnravelOutput_TargetScript.ps1 b/Tasks/AzurePowerShellV4/Tests/DoesNotUnravelOutput_TargetScript.ps1 deleted file mode 100644 index 3c82d4ce2901..000000000000 --- a/Tasks/AzurePowerShellV4/Tests/DoesNotUnravelOutput_TargetScript.ps1 +++ /dev/null @@ -1,5 +0,0 @@ -# Return an array. -,@( 'item 1', 'item 2') - -# Return an item. -'item 3' \ No newline at end of file diff --git a/Tasks/AzurePowerShellV4/Tests/FailsForNativeCommandError.ps1 b/Tasks/AzurePowerShellV4/Tests/FailsForNativeCommandError.ps1 deleted file mode 100644 index d6010a64f053..000000000000 --- a/Tasks/AzurePowerShellV4/Tests/FailsForNativeCommandError.ps1 +++ /dev/null @@ -1,22 +0,0 @@ -[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-AzModule -Register-Mock Remove-EndpointSecrets -Register-Mock Disconnect-AzureAndClearContext -Register-Mock Get-VstsEndpoint -Register-Mock Assert-VstsPath -Register-Mock Invoke-VstsTool { } - -# Act. -$actual = @( & $PSScriptRoot\..\AzurePowerShell.ps1 ) -$global:ErrorActionPreference = 'Stop' # Reset to stop. \ No newline at end of file diff --git a/Tasks/AzurePowerShellV4/Tests/L0.ts b/Tasks/AzurePowerShellV4/Tests/L0.ts index cd89d48d4bdb..52f4c31bb086 100644 --- a/Tasks/AzurePowerShellV4/Tests/L0.ts +++ b/Tasks/AzurePowerShellV4/Tests/L0.ts @@ -27,21 +27,9 @@ describe('AzurePowerShell Suite', function () { }); if (psm.testSupported()) { - it('does not unravel output', (done) => { - psr.run(path.join(__dirname, 'DoesNotUnravelOutput.ps1'), done); - }) it('performs basic flow', (done) => { psr.run(path.join(__dirname, 'PerformsBasicFlow.ps1'), done); }) - it('validates inline script flow', (done) => { - psr.run(path.join(__dirname, 'ValidateInlineScriptFlow.ps1'), done); - }) - it('redirects errors', (done) => { - psr.run(path.join(__dirname, 'RedirectsErrors.ps1'), done); - }) - it('does not fail if failonstandarderror is set to false', (done) => { - psr.run(path.join(__dirname, 'DoesNotFailOnStandardError.ps1'), done); - }) it('removes functions and variables', (done) => { psr.run(path.join(__dirname, 'RemovesFunctionsAndVariables.ps1'), done); }) @@ -54,12 +42,6 @@ describe('AzurePowerShell Suite', function () { it('throws when invalid script path', (done) => { psr.run(path.join(__dirname, 'ThrowsWhenInvalidScriptPath.ps1'), done); }) - it('does not fail if native command writes to stderr and failonstderr is false', (done) => { - psr.run(path.join(__dirname, 'DoesNotThrowForNativeCommandError.ps1'), done); - }) - it('fails for native command error if fail on standard error is true', (done) => { - psr.run(path.join(__dirname, 'FailsForNativeCommandError.ps1'), done); - }) it('Get-LatestModule returns the latest available module', (done) => { psr.run(path.join(__dirname, 'Utility.Get-LatestModule.ps1'), done); }) diff --git a/Tasks/AzurePowerShellV4/Tests/NativeCommandError_TargetScript.ps1 b/Tasks/AzurePowerShellV4/Tests/NativeCommandError_TargetScript.ps1 deleted file mode 100644 index 6061993292ac..000000000000 --- a/Tasks/AzurePowerShellV4/Tests/NativeCommandError_TargetScript.ps1 +++ /dev/null @@ -1,3 +0,0 @@ -Write-Output "output 1" -OPENFILES M:/rok -Write-Output "output 2" \ No newline at end of file diff --git a/Tasks/AzurePowerShellV4/Tests/RedirectsErrors.ps1 b/Tasks/AzurePowerShellV4/Tests/RedirectsErrors.ps1 deleted file mode 100644 index 3d530fcd59e1..000000000000 --- a/Tasks/AzurePowerShellV4/Tests/RedirectsErrors.ps1 +++ /dev/null @@ -1,22 +0,0 @@ -[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 { $true } -- -Name FailOnStandardError -Register-Mock Update-PSModulePathForHostedAgent -Register-Mock Initialize-AzModule -Register-Mock Remove-EndpointSecrets -Register-Mock Disconnect-AzureAndClearContext -Register-Mock Get-VstsEndpoint -Register-Mock Assert-VstsPath -Register-Mock Invoke-VstsTool { } - -# Act. -$actual = @( & $PSScriptRoot\..\AzurePowerShell.ps1 ) -$global:ErrorActionPreference = 'Stop' # Reset to stop. diff --git a/Tasks/AzurePowerShellV4/Tests/RedirectsErrors_TargetScript.ps1 b/Tasks/AzurePowerShellV4/Tests/RedirectsErrors_TargetScript.ps1 deleted file mode 100644 index 06051b017db8..000000000000 --- a/Tasks/AzurePowerShellV4/Tests/RedirectsErrors_TargetScript.ps1 +++ /dev/null @@ -1,4 +0,0 @@ -"Some output 1" -Write-Error "Some error 1" -"Some output 2" -Write-Error "Some error 2" \ No newline at end of file diff --git a/Tasks/AzurePowerShellV4/Tests/ValidateInlineScriptFlow.ps1 b/Tasks/AzurePowerShellV4/Tests/ValidateInlineScriptFlow.ps1 deleted file mode 100644 index e01d36e19f25..000000000000 --- a/Tasks/AzurePowerShellV4/Tests/ValidateInlineScriptFlow.ps1 +++ /dev/null @@ -1,26 +0,0 @@ -[CmdletBinding()] -param() - -# Arrange. -. $PSScriptRoot\..\..\..\Tests\lib\Initialize-Test.ps1 -Unregister-Mock Get-VstsInput -$targetAzurePs = "4.1.0" -if([string]::IsNullOrEmpty($env:Agent_TempDirectory)) { - $env:Agent_TempDirectory = $env:TEMP -} -Register-Mock Get-VstsInput { "InlineScript" } -- -Name ScriptType -Require -Register-Mock Get-VstsInput { ",@( 'item 1', 'item 2')" } -- -Name Inline -Register-Mock Get-VstsInput { $targetAzurePs } -- -Name TargetAzurePs -Register-Mock Get-VstsInput { "continue" } -- -Name errorActionPreference -Register-Mock Get-VstsInput { $true } -- -Name FailOnStandardError -Register-Mock Update-PSModulePathForHostedAgent -Register-Mock Initialize-AzModule -Register-Mock Remove-EndpointSecrets -Register-Mock Disconnect-AzureAndClearContext -Register-Mock Get-VstsEndpoint -Register-Mock Assert-VstsPath -Register-Mock Invoke-VstsTool { } - -# Act. -$actual = @( & $PSScriptRoot\..\AzurePowerShell.ps1 ) -$global:ErrorActionPreference = 'Stop' # Reset to stop. \ No newline at end of file From c36228a789f9ef563f36a644f571088c5388b53b Mon Sep 17 00:00:00 2001 From: Shivangi Date: Tue, 17 Sep 2019 10:57:09 +0530 Subject: [PATCH 5/8] Adding L0 test --- Tasks/AzurePowerShellV4/AzurePowerShell.ps1 | 2 +- .../Tests/ChecksForPowerShellCore.ps1 | 28 +++++++++++++ Tasks/AzurePowerShellV4/Tests/L0.ts | 6 +-- .../Tests/RemovesFunctionsAndVariables.ps1 | 41 ------------------- ...ovesFunctionsAndVariables_TargetScript.ps1 | 14 ------- 5 files changed, 32 insertions(+), 59 deletions(-) create mode 100644 Tasks/AzurePowerShellV4/Tests/ChecksForPowerShellCore.ps1 delete mode 100644 Tasks/AzurePowerShellV4/Tests/RemovesFunctionsAndVariables.ps1 delete mode 100644 Tasks/AzurePowerShellV4/Tests/RemovesFunctionsAndVariables_TargetScript.ps1 diff --git a/Tasks/AzurePowerShellV4/AzurePowerShell.ps1 b/Tasks/AzurePowerShellV4/AzurePowerShell.ps1 index a94665d36b07..318d59c03c60 100644 --- a/Tasks/AzurePowerShellV4/AzurePowerShell.ps1 +++ b/Tasks/AzurePowerShellV4/AzurePowerShell.ps1 @@ -10,7 +10,7 @@ $__vsts_input_errorActionPreference = Get-VstsInput -Name errorActionPreference $__vsts_input_failOnStandardError = Get-VstsInput -Name FailOnStandardError $targetAzurePs = Get-VstsInput -Name TargetAzurePs $customTargetAzurePs = Get-VstsInput -Name CustomTargetAzurePs -$input_pwsh = Get-VstsInput -Name 'pwsh' -AsBool +$input_pwsh = Get-VstsInput -Name 'pwsh' $input_workingDirectory = Get-VstsInput -Name 'workingDirectory' -Require # Validate the script path and args do not contains new-lines. Otherwise, it will diff --git a/Tasks/AzurePowerShellV4/Tests/ChecksForPowerShellCore.ps1 b/Tasks/AzurePowerShellV4/Tests/ChecksForPowerShellCore.ps1 new file mode 100644 index 000000000000..4ed3376b5ac6 --- /dev/null +++ b/Tasks/AzurePowerShellV4/Tests/ChecksForPowerShellCore.ps1 @@ -0,0 +1,28 @@ +[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/PerformsBasicFlow_TargetScript.ps1" } -- -Name ScriptPath +Register-Mock Get-VstsInput { $targetAzurePs } -- -Name TargetAzurePs +Register-Mock Get-VstsInput { 'arg1 arg2' } -- -Name ScriptArguments +Register-Mock Get-VstsInput { "continue" } -- -Name errorActionPreference +Register-Mock Get-VstsInput { $true } -- -Name FailOnStandardError +Register-Mock Get-VstsInput { $true } -- -Name pwsh +Register-Mock Get-VstsInput { ([System.IO.Path]::GetTempPath()) } -- -Name workingDirectory +Register-Mock Update-PSModulePathForHostedAgent +Register-Mock Get-Module +Register-Mock Initialize-AzModule +Register-Mock Get-VstsEndpoint { @{auth = @{ scheme = "ServicePrincipal" }} } +Register-Mock Remove-EndpointSecrets +Register-Mock Disconnect-AzureAndClearContext +Register-Mock Assert-VstsPath +Register-Mock Invoke-VstsTool { } + +# Act. +$actual = & $PSScriptRoot\..\AzurePowerShell.ps1 + +Assert-WasCalled Invoke-VstsTool -Times 1 +Assert-WasCalled Invoke-VstsTool -ArgumentsEvaluator {$args.count -eq 6 -and $args[3] -like '*pwsh.exe*'} \ No newline at end of file diff --git a/Tasks/AzurePowerShellV4/Tests/L0.ts b/Tasks/AzurePowerShellV4/Tests/L0.ts index 52f4c31bb086..6f7546d09e32 100644 --- a/Tasks/AzurePowerShellV4/Tests/L0.ts +++ b/Tasks/AzurePowerShellV4/Tests/L0.ts @@ -27,12 +27,12 @@ describe('AzurePowerShell Suite', function () { }); if (psm.testSupported()) { + it('checks for powershell core', (done) => { + psr.run(path.join(__dirname, 'ChecksForPowerShellCore.ps1'), done); + }) it('performs basic flow', (done) => { psr.run(path.join(__dirname, 'PerformsBasicFlow.ps1'), done); }) - it('removes functions and variables', (done) => { - psr.run(path.join(__dirname, 'RemovesFunctionsAndVariables.ps1'), done); - }) it('throws when otherversion is specified in a wrong format', (done) => { psr.run(path.join(__dirname, 'ThrowsForInvalidVersion.ps1'), done); }) diff --git a/Tasks/AzurePowerShellV4/Tests/RemovesFunctionsAndVariables.ps1 b/Tasks/AzurePowerShellV4/Tests/RemovesFunctionsAndVariables.ps1 deleted file mode 100644 index 876235588bc7..000000000000 --- a/Tasks/AzurePowerShellV4/Tests/RemovesFunctionsAndVariables.ps1 +++ /dev/null @@ -1,41 +0,0 @@ -[CmdletBinding()] -param() - -# Arrange. -. $PSScriptRoot\..\..\..\Tests\lib\Initialize-Test.ps1 - -# Arrange the task inputs. -$targetAzurePs = "4.1.0" -Register-Mock Get-VstsInput { "FilePath" } -- -Name ScriptType -Require -Register-Mock Get-VstsInput { "$PSScriptRoot/RemovesFunctionsAndVariables_TargetScript.ps1" } -- -Name ScriptPath -Register-Mock Get-VstsInput { $targetAzurePs } -- -Name TargetAzurePs -Register-Mock Get-VstsInput { "continue" } -- -Name errorActionPreference -Register-Mock Get-VstsInput { $true } -- -Name FailOnStandardError -Register-Mock Update-PSModulePathForHostedAgent -Register-Mock Remove-EndpointSecrets -Register-Mock Disconnect-AzureAndClearContext -Register-Mock Get-VstsEndpoint -Register-Mock Assert-VstsPath -Register-Mock Invoke-VstsTool { } - -# Arrange the mock task SDK module. -New-Module -Name VstsTaskSdk -ScriptBlock { - function SomeVstsTaskSdkFunction1 { } - function SomeVstsTaskSdkFunction2 { } - function Out-Default { } -} -function Invoke-VstsTaskScript { } # Detached from the task SDK module -$null = Get-Item function:SomeVstsTaskSdkFunction1 # Sanity check to verify the function was imported. - -# Arrange the mock Azure helpers module. -Register-Mock Initialize-AzModule -Register-Mock Initialize-AzureRMModule -New-Module -Name VstsAzureHelpers_ -ScriptBlock { - function SomeAzureHelpersFunction1 { } - function SomeAzureHelpersFunction2 { } -} -$null = Get-Item function:SomeAzureHelpersFunction1 # Sanity check to verify the function was imported. - -# Act. -$actual = & $PSScriptRoot\..\AzurePowerShell.ps1 -$global:ErrorActionPreference = 'Stop' # Reset to stop. diff --git a/Tasks/AzurePowerShellV4/Tests/RemovesFunctionsAndVariables_TargetScript.ps1 b/Tasks/AzurePowerShellV4/Tests/RemovesFunctionsAndVariables_TargetScript.ps1 deleted file mode 100644 index c88c45cfcc2d..000000000000 --- a/Tasks/AzurePowerShellV4/Tests/RemovesFunctionsAndVariables_TargetScript.ps1 +++ /dev/null @@ -1,14 +0,0 @@ -# Return key information. -$result = New-Object psobject -Property @{ - FunctionNames = @{ } - VariableNames = @{ } -} -foreach ($function in (Get-ChildItem function:)) { - $result.FunctionNames[$function.Name] = $function.Name -} - -foreach ($variable in (Get-ChildItem variable:)) { - $result.VariableNames[$variable.Name] = $variable.Name -} - -$result \ No newline at end of file From 59f498832aa72e83b8458691a4597e922486b686 Mon Sep 17 00:00:00 2001 From: Shivangi Date: Tue, 17 Sep 2019 11:13:13 +0530 Subject: [PATCH 6/8] Changing minor version --- Tasks/AzurePowerShellV4/task.json | 2 +- Tasks/AzurePowerShellV4/task.loc.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Tasks/AzurePowerShellV4/task.json b/Tasks/AzurePowerShellV4/task.json index 43dc1d69dbb8..90c181a7bb86 100644 --- a/Tasks/AzurePowerShellV4/task.json +++ b/Tasks/AzurePowerShellV4/task.json @@ -16,7 +16,7 @@ "author": "Microsoft Corporation", "version": { "Major": 4, - "Minor": 158, + "Minor": 159, "Patch": 0 }, "preview": true, diff --git a/Tasks/AzurePowerShellV4/task.loc.json b/Tasks/AzurePowerShellV4/task.loc.json index b214dd5ba784..15f6bf189bed 100644 --- a/Tasks/AzurePowerShellV4/task.loc.json +++ b/Tasks/AzurePowerShellV4/task.loc.json @@ -16,7 +16,7 @@ "author": "Microsoft Corporation", "version": { "Major": 4, - "Minor": 158, + "Minor": 159, "Patch": 0 }, "preview": true, From b004db3cb733756827dfb24b1339b40d823e625b Mon Sep 17 00:00:00 2001 From: Shivangi Date: Tue, 17 Sep 2019 12:45:53 +0530 Subject: [PATCH 7/8] adding more L0 tests --- Tasks/AzurePowerShellV4/AzurePowerShell.ps1 | 4 +-- .../Tests/ChecksForPowerShell.ps1 | 27 +++++++++++++++++ .../Tests/ChecksForPowerShellCore.ps1 | 3 +- .../Tests/ChecksForWorkingDirectory.ps1 | 29 +++++++++++++++++++ Tasks/AzurePowerShellV4/Tests/L0.ts | 6 ++++ 5 files changed, 65 insertions(+), 4 deletions(-) create mode 100644 Tasks/AzurePowerShellV4/Tests/ChecksForPowerShell.ps1 create mode 100644 Tasks/AzurePowerShellV4/Tests/ChecksForWorkingDirectory.ps1 diff --git a/Tasks/AzurePowerShellV4/AzurePowerShell.ps1 b/Tasks/AzurePowerShellV4/AzurePowerShell.ps1 index 318d59c03c60..4054e81b1e5b 100644 --- a/Tasks/AzurePowerShellV4/AzurePowerShell.ps1 +++ b/Tasks/AzurePowerShellV4/AzurePowerShell.ps1 @@ -10,8 +10,8 @@ $__vsts_input_errorActionPreference = Get-VstsInput -Name errorActionPreference $__vsts_input_failOnStandardError = Get-VstsInput -Name FailOnStandardError $targetAzurePs = Get-VstsInput -Name TargetAzurePs $customTargetAzurePs = Get-VstsInput -Name CustomTargetAzurePs -$input_pwsh = Get-VstsInput -Name 'pwsh' -$input_workingDirectory = Get-VstsInput -Name 'workingDirectory' -Require +$input_pwsh = Get-VstsInput -Name pwsh +$input_workingDirectory = Get-VstsInput -Name workingDirectory -Require # Validate the script path and args do not contains new-lines. Otherwise, it will # break invoking the script via Invoke-Expression. diff --git a/Tasks/AzurePowerShellV4/Tests/ChecksForPowerShell.ps1 b/Tasks/AzurePowerShellV4/Tests/ChecksForPowerShell.ps1 new file mode 100644 index 000000000000..518af4fd43c6 --- /dev/null +++ b/Tasks/AzurePowerShellV4/Tests/ChecksForPowerShell.ps1 @@ -0,0 +1,27 @@ +[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/PerformsBasicFlow_TargetScript.ps1" } -- -Name ScriptPath +Register-Mock Get-VstsInput { $targetAzurePs } -- -Name TargetAzurePs +Register-Mock Get-VstsInput { 'arg1 arg2' } -- -Name ScriptArguments +Register-Mock Get-VstsInput { "continue" } -- -Name errorActionPreference +Register-Mock Get-VstsInput { $true } -- -Name FailOnStandardError +Register-Mock Get-VstsInput { $false } -- -Name pwsh +Register-Mock Update-PSModulePathForHostedAgent +Register-Mock Get-Module +Register-Mock Initialize-AzModule +Register-Mock Get-VstsEndpoint { @{auth = @{ scheme = "ServicePrincipal" }} } +Register-Mock Remove-EndpointSecrets +Register-Mock Disconnect-AzureAndClearContext +Register-Mock Assert-VstsPath +Register-Mock Invoke-VstsTool { } + +# Act. +$actual = & $PSScriptRoot\..\AzurePowerShell.ps1 + +Assert-WasCalled Invoke-VstsTool -Times 1 +Assert-WasCalled Invoke-VstsTool -ArgumentsEvaluator {($args | ConvertTo-Json) -like '*powershell.exe*'} \ No newline at end of file diff --git a/Tasks/AzurePowerShellV4/Tests/ChecksForPowerShellCore.ps1 b/Tasks/AzurePowerShellV4/Tests/ChecksForPowerShellCore.ps1 index 4ed3376b5ac6..dbd0a545f3fc 100644 --- a/Tasks/AzurePowerShellV4/Tests/ChecksForPowerShellCore.ps1 +++ b/Tasks/AzurePowerShellV4/Tests/ChecksForPowerShellCore.ps1 @@ -11,7 +11,6 @@ Register-Mock Get-VstsInput { 'arg1 arg2' } -- -Name ScriptArguments Register-Mock Get-VstsInput { "continue" } -- -Name errorActionPreference Register-Mock Get-VstsInput { $true } -- -Name FailOnStandardError Register-Mock Get-VstsInput { $true } -- -Name pwsh -Register-Mock Get-VstsInput { ([System.IO.Path]::GetTempPath()) } -- -Name workingDirectory Register-Mock Update-PSModulePathForHostedAgent Register-Mock Get-Module Register-Mock Initialize-AzModule @@ -25,4 +24,4 @@ Register-Mock Invoke-VstsTool { } $actual = & $PSScriptRoot\..\AzurePowerShell.ps1 Assert-WasCalled Invoke-VstsTool -Times 1 -Assert-WasCalled Invoke-VstsTool -ArgumentsEvaluator {$args.count -eq 6 -and $args[3] -like '*pwsh.exe*'} \ No newline at end of file +Assert-WasCalled Invoke-VstsTool -ArgumentsEvaluator {($args | ConvertTo-Json) -like '*pwsh.exe*'} \ No newline at end of file diff --git a/Tasks/AzurePowerShellV4/Tests/ChecksForWorkingDirectory.ps1 b/Tasks/AzurePowerShellV4/Tests/ChecksForWorkingDirectory.ps1 new file mode 100644 index 000000000000..e1664f850916 --- /dev/null +++ b/Tasks/AzurePowerShellV4/Tests/ChecksForWorkingDirectory.ps1 @@ -0,0 +1,29 @@ +[CmdletBinding()] +param() + +# Arrange. +. $PSScriptRoot\..\..\..\Tests\lib\Initialize-Test.ps1 +$targetAzurePs = "4.1.0" +$input_workingDirectory = "C:\Users" +Register-Mock Get-VstsInput { "FilePath" } -- -Name ScriptType -Require +Register-Mock Get-VstsInput { "$PSScriptRoot/PerformsBasicFlow_TargetScript.ps1" } -- -Name ScriptPath +Register-Mock Get-VstsInput { $targetAzurePs } -- -Name TargetAzurePs +Register-Mock Get-VstsInput { 'arg1 arg2' } -- -Name ScriptArguments +Register-Mock Get-VstsInput { "continue" } -- -Name errorActionPreference +Register-Mock Get-VstsInput { $true } -- -Name FailOnStandardError +Register-Mock Get-VstsInput { $true } -- -Name pwsh +Register-Mock Get-VstsInput { $input_workingDirectory } -- -Name workingDirectory -Require +Register-Mock Update-PSModulePathForHostedAgent +Register-Mock Get-Module +Register-Mock Initialize-AzModule +Register-Mock Get-VstsEndpoint { @{auth = @{ scheme = "ServicePrincipal" }} } +Register-Mock Remove-EndpointSecrets +Register-Mock Disconnect-AzureAndClearContext +Register-Mock Assert-VstsPath +Register-Mock Invoke-VstsTool { } + +# Act. +$actual = & $PSScriptRoot\..\AzurePowerShell.ps1 + +Assert-WasCalled Invoke-VstsTool -Times 1 +Assert-WasCalled Invoke-VstsTool -ArgumentsEvaluator {($args | ConvertTo-Json) -like '*C:\\Users*'} \ No newline at end of file diff --git a/Tasks/AzurePowerShellV4/Tests/L0.ts b/Tasks/AzurePowerShellV4/Tests/L0.ts index 6f7546d09e32..419e7a10004e 100644 --- a/Tasks/AzurePowerShellV4/Tests/L0.ts +++ b/Tasks/AzurePowerShellV4/Tests/L0.ts @@ -30,6 +30,12 @@ describe('AzurePowerShell Suite', function () { it('checks for powershell core', (done) => { psr.run(path.join(__dirname, 'ChecksForPowerShellCore.ps1'), done); }) + it('checks for powershell', (done) => { + psr.run(path.join(__dirname, 'ChecksForPowerShell.ps1'), done); + }) + it('checks for working directory', (done) => { + psr.run(path.join(__dirname, 'ChecksForWorkingDirectory.ps1'), done); + }) it('performs basic flow', (done) => { psr.run(path.join(__dirname, 'PerformsBasicFlow.ps1'), done); }) From ccb8f52a1e728968c79cdfaf7c8d69f96f1edc3d Mon Sep 17 00:00:00 2001 From: Shivangi Date: Tue, 17 Sep 2019 15:47:31 +0530 Subject: [PATCH 8/8] adding bool --- Tasks/AzurePowerShellV4/AzurePowerShell.ps1 | 2 +- Tasks/AzurePowerShellV4/Tests/ChecksForPowerShell.ps1 | 2 +- Tasks/AzurePowerShellV4/Tests/ChecksForPowerShellCore.ps1 | 2 +- Tasks/AzurePowerShellV4/Tests/ChecksForWorkingDirectory.ps1 | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Tasks/AzurePowerShellV4/AzurePowerShell.ps1 b/Tasks/AzurePowerShellV4/AzurePowerShell.ps1 index 4054e81b1e5b..8a5bc2888cec 100644 --- a/Tasks/AzurePowerShellV4/AzurePowerShell.ps1 +++ b/Tasks/AzurePowerShellV4/AzurePowerShell.ps1 @@ -10,7 +10,7 @@ $__vsts_input_errorActionPreference = Get-VstsInput -Name errorActionPreference $__vsts_input_failOnStandardError = Get-VstsInput -Name FailOnStandardError $targetAzurePs = Get-VstsInput -Name TargetAzurePs $customTargetAzurePs = Get-VstsInput -Name CustomTargetAzurePs -$input_pwsh = Get-VstsInput -Name pwsh +$input_pwsh = Get-VstsInput -Name pwsh -AsBool $input_workingDirectory = Get-VstsInput -Name workingDirectory -Require # Validate the script path and args do not contains new-lines. Otherwise, it will diff --git a/Tasks/AzurePowerShellV4/Tests/ChecksForPowerShell.ps1 b/Tasks/AzurePowerShellV4/Tests/ChecksForPowerShell.ps1 index 518af4fd43c6..749530f76757 100644 --- a/Tasks/AzurePowerShellV4/Tests/ChecksForPowerShell.ps1 +++ b/Tasks/AzurePowerShellV4/Tests/ChecksForPowerShell.ps1 @@ -10,7 +10,7 @@ Register-Mock Get-VstsInput { $targetAzurePs } -- -Name TargetAzurePs Register-Mock Get-VstsInput { 'arg1 arg2' } -- -Name ScriptArguments Register-Mock Get-VstsInput { "continue" } -- -Name errorActionPreference Register-Mock Get-VstsInput { $true } -- -Name FailOnStandardError -Register-Mock Get-VstsInput { $false } -- -Name pwsh +Register-Mock Get-VstsInput { $false } -- -Name pwsh -AsBool Register-Mock Update-PSModulePathForHostedAgent Register-Mock Get-Module Register-Mock Initialize-AzModule diff --git a/Tasks/AzurePowerShellV4/Tests/ChecksForPowerShellCore.ps1 b/Tasks/AzurePowerShellV4/Tests/ChecksForPowerShellCore.ps1 index dbd0a545f3fc..6bfb4ea83f32 100644 --- a/Tasks/AzurePowerShellV4/Tests/ChecksForPowerShellCore.ps1 +++ b/Tasks/AzurePowerShellV4/Tests/ChecksForPowerShellCore.ps1 @@ -10,7 +10,7 @@ Register-Mock Get-VstsInput { $targetAzurePs } -- -Name TargetAzurePs Register-Mock Get-VstsInput { 'arg1 arg2' } -- -Name ScriptArguments Register-Mock Get-VstsInput { "continue" } -- -Name errorActionPreference Register-Mock Get-VstsInput { $true } -- -Name FailOnStandardError -Register-Mock Get-VstsInput { $true } -- -Name pwsh +Register-Mock Get-VstsInput { $true } -- -Name pwsh -AsBool Register-Mock Update-PSModulePathForHostedAgent Register-Mock Get-Module Register-Mock Initialize-AzModule diff --git a/Tasks/AzurePowerShellV4/Tests/ChecksForWorkingDirectory.ps1 b/Tasks/AzurePowerShellV4/Tests/ChecksForWorkingDirectory.ps1 index e1664f850916..27905b95eac1 100644 --- a/Tasks/AzurePowerShellV4/Tests/ChecksForWorkingDirectory.ps1 +++ b/Tasks/AzurePowerShellV4/Tests/ChecksForWorkingDirectory.ps1 @@ -11,7 +11,7 @@ Register-Mock Get-VstsInput { $targetAzurePs } -- -Name TargetAzurePs Register-Mock Get-VstsInput { 'arg1 arg2' } -- -Name ScriptArguments Register-Mock Get-VstsInput { "continue" } -- -Name errorActionPreference Register-Mock Get-VstsInput { $true } -- -Name FailOnStandardError -Register-Mock Get-VstsInput { $true } -- -Name pwsh +Register-Mock Get-VstsInput { $true } -- -Name pwsh -AsBool Register-Mock Get-VstsInput { $input_workingDirectory } -- -Name workingDirectory -Require Register-Mock Update-PSModulePathForHostedAgent Register-Mock Get-Module