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

[PowershellV2] Fix powershell execution script to fail on wrong targettype #15026

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@
"loc.messages.JS_InvalidErrorActionPreference": "Invalid ErrorActionPreference '%s'. The value must be one of: 'Stop', 'Continue', or 'SilentlyContinue'",
"loc.messages.JS_InvalidFilePath": "Invalid file path '%s'. A path to a .ps1 file is required.",
"loc.messages.JS_Stderr": "PowerShell wrote one or more lines to the standard error stream.",
"loc.messages.JS_InvalidTargetType": "Invalid target type '%s'. The value must be one of: 'filepath' or 'inline'",
"loc.messages.PS_ExitCode": "PowerShell exited with code '{0}'.",
"loc.messages.PS_FormattedCommand": "Formatted command: {0}",
"loc.messages.PS_InvalidErrorActionPreference": "Invalid ErrorActionPreference '{0}'. The value must be one of: 'Stop', 'Continue', or 'SilentlyContinue'",
"loc.messages.PS_InvalidFilePath": "Invalid file path '{0}'. A path to a .ps1 file is required.",
"loc.messages.PS_UnableToDetermineExitCode": "Unexpected exception. Unable to determine the exit code from powershell."
"loc.messages.PS_UnableToDetermineExitCode": "Unexpected exception. Unable to determine the exit code from powershell.",
"loc.messages.PS_InvalidTargetType": "Invalid target type '{0}'. The value must be one of: 'filepath' or 'inline'"
}
5 changes: 4 additions & 1 deletion Tasks/PowerShellV2/powershell.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@ try {

$input_arguments = Get-VstsInput -Name 'arguments'
}
else {
elseif("$input_targetType".ToUpperInvariant() -eq "INLINE") {
$input_script = Get-VstsInput -Name 'script'
}
else {
Write-Error (Get-VstsLocString -Key 'PS_InvalidTargetType' -ArgumentList $input_targetType)
}
$input_runScriptInSeparateScope = Get-VstsInput -Name 'runScriptInSeparateScope' -AsBool

# Generate the script contents.
Expand Down
2 changes: 1 addition & 1 deletion Tasks/PowerShellV2/powershell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async function run() {
input_script = tl.getInput('script', false) || '';
}
else {
throw new Error(tl.loc('PS_InvalidTargetType', input_targetType));
throw new Error(tl.loc('JS_InvalidTargetType', input_targetType));
}
const input_runScriptInSeparateScope = tl.getBoolInput('runScriptInSeparateScope');

Expand Down
6 changes: 4 additions & 2 deletions 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": 189,
"Minor": 190,
"Patch": 0
},
"releaseNotes": "Script task consistency. Added support for macOS and Linux.",
Expand Down Expand Up @@ -163,10 +163,12 @@
"JS_InvalidErrorActionPreference": "Invalid ErrorActionPreference '%s'. The value must be one of: 'Stop', 'Continue', or 'SilentlyContinue'",
"JS_InvalidFilePath": "Invalid file path '%s'. A path to a .ps1 file is required.",
"JS_Stderr": "PowerShell wrote one or more lines to the standard error stream.",
"JS_InvalidTargetType": "Invalid target type '%s'. The value must be one of: 'filepath' or 'inline'",
"PS_ExitCode": "PowerShell exited with code '{0}'.",
"PS_FormattedCommand": "Formatted command: {0}",
"PS_InvalidErrorActionPreference": "Invalid ErrorActionPreference '{0}'. The value must be one of: 'Stop', 'Continue', or 'SilentlyContinue'",
"PS_InvalidFilePath": "Invalid file path '{0}'. A path to a .ps1 file is required.",
"PS_UnableToDetermineExitCode": "Unexpected exception. Unable to determine the exit code from powershell."
"PS_UnableToDetermineExitCode": "Unexpected exception. Unable to determine the exit code from powershell.",
"PS_InvalidTargetType": "Invalid target type '{0}'. The value must be one of: 'filepath' or 'inline'"
}
}
6 changes: 4 additions & 2 deletions 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": 189,
"Minor": 190,
"Patch": 0
},
"releaseNotes": "ms-resource:loc.releaseNotes",
Expand Down Expand Up @@ -163,10 +163,12 @@
"JS_InvalidErrorActionPreference": "ms-resource:loc.messages.JS_InvalidErrorActionPreference",
"JS_InvalidFilePath": "ms-resource:loc.messages.JS_InvalidFilePath",
"JS_Stderr": "ms-resource:loc.messages.JS_Stderr",
"JS_InvalidTargetType": "ms-resource:loc.messages.JS_InvalidTargetType",
"PS_ExitCode": "ms-resource:loc.messages.PS_ExitCode",
"PS_FormattedCommand": "ms-resource:loc.messages.PS_FormattedCommand",
"PS_InvalidErrorActionPreference": "ms-resource:loc.messages.PS_InvalidErrorActionPreference",
"PS_InvalidFilePath": "ms-resource:loc.messages.PS_InvalidFilePath",
"PS_UnableToDetermineExitCode": "ms-resource:loc.messages.PS_UnableToDetermineExitCode"
"PS_UnableToDetermineExitCode": "ms-resource:loc.messages.PS_UnableToDetermineExitCode",
"PS_InvalidTargetType": "ms-resource:loc.messages.PS_InvalidTargetType"
}
}