Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PowerShellV2 task for old PowerShell versions #18904

Merged
merged 9 commits into from
Sep 12, 2023
5 changes: 0 additions & 5 deletions Tasks/PowerShellV2/errors.ps1

This file was deleted.

6 changes: 2 additions & 4 deletions Tasks/PowerShellV2/helpers.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
. $PSScriptRoot\errors.ps1

function Publish-Telemetry($Telemetry) {
$area = 'TaskHub'
$feature = 'PowerShellV2'
Expand Down Expand Up @@ -220,7 +218,7 @@ function Test-FileArgs([string]$inputArguments) {
}

## get values of all keys
Write-Debug "Feature flags state: @featureFlags"
Write-Debug "Feature flags state: $($featureFlags | ConvertTo-Json -Compress)"

if ($featureFlags.activate -or $featureFlags.audit -or $featureFlags.telemetry) {
Write-Debug "Validating file arguments."
Expand All @@ -240,7 +238,7 @@ function Test-FileArgs([string]$inputArguments) {
if ($sanitizedArgs -ne $expandedArgs) {
$message = Get-VstsLocString -Key 'ScriptArgsSanitized';
if ($featureFlags.activate) {
throw [ArgsSanitizingException] $message;
throw $message;
}
if ($featureFlags.audit) {
Write-Warning $message;
Expand Down
12 changes: 7 additions & 5 deletions Tasks/PowerShellV2/powershell.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
param()

. $PSScriptRoot\helpers.ps1
. $PSScriptRoot\errors.ps1

function Get-ActionPreference {
param (
Expand Down Expand Up @@ -99,12 +98,15 @@ try {
try {
Test-FileArgs $input_arguments
}
catch [ArgsSanitizingException] {
throw
}
catch {
$message = $_.Exception.Message

if ($message -eq (Get-VstsLocString -Key 'ScriptArgsSanitized')) {
throw $message;
}

$telemetry = @{
'UnexpectedError' = $_.Exception.Message
'UnexpectedError' = $message
'ErrorStackTrace' = $_.Exception.StackTrace
}
Publish-Telemetry $telemetry
Expand Down
2 changes: 1 addition & 1 deletion Tasks/PowerShellV2/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 2,
"Minor": 227,
"Minor": 228,
"Patch": 0
},
"releaseNotes": "Script task consistency. Added support for macOS and Linux.",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/PowerShellV2/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 2,
"Minor": 227,
"Minor": 228,
"Patch": 0
},
"releaseNotes": "ms-resource:loc.releaseNotes",
Expand Down