Skip to content

Commit

Permalink
1914047 Make PS task faster by removing the calls to get progress info
Browse files Browse the repository at this point in the history
…#3396 (#16758)

* 1914047 Make PS task faster by removing the calls to get progress info #3396

-- added option progressPreference to PowershellTask to control the way progress is reported.
-- set default option as 'SilentlyContinue'

* 1914047 Make PS task faster by removing the calls to get progress info #3396

-- Fixed test cases

* 1914047 Make PS task faster by removing the calls to get progress info #3396

-- Fixed localization

* 1914047 Make PS task faster by removing the calls to get progress info #3396

-- Fixed localization

Co-authored-by: Kirill Ivlev <102740624+kirill-ivlev@users.noreply.github.com>
Co-authored-by: Maxim Zaytsev <v-mazayt@microsoft.com>
Co-authored-by: AndreyIvanov42 <93121155+AndreyIvanov42@users.noreply.github.com>
  • Loading branch information
4 people authored Aug 29, 2022
1 parent ed2f79d commit 71408f9
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@
"loc.input.help.arguments": "Arguments passed to the PowerShell script. Either ordinal parameters or named parameters.",
"loc.input.label.script": "Script",
"loc.input.label.errorActionPreference": "ErrorActionPreference",
"loc.input.label.warningPreference": "WarningPreference",
"loc.input.label.informationPreference": "InformationPreference",
"loc.input.label.verbosePreference": "VerbosePreference",
"loc.input.label.debugPreference": "DebugPreference",
"loc.input.help.errorActionPreference": "When not `Default`, prepends the line `$ErrorActionPreference = 'VALUE'` at the top of your script.",
"loc.input.label.warningPreference": "WarningPreference",
"loc.input.help.warningPreference": "When not `Default`, prepends the line `$WarningPreference = 'VALUE'` at the top of your script.",
"loc.input.label.informationPreference": "InformationPreference",
"loc.input.help.informationPreference": "When not `Default`, prepends the line `$InformationPreference = 'VALUE'` at the top of your script.",
"loc.input.label.verbosePreference": "VerbosePreference",
"loc.input.help.verbosePreference": "When not `Default`, prepends the line `$VerbosePreference = 'VALUE'` at the top of your script.",
"loc.input.label.debugPreference": "DebugPreference",
"loc.input.help.debugPreference": "When not `Default`, prepends the line `$DebugPreference = 'VALUE'` at the top of your script.",
"loc.input.label.progressPreference": "ProgressPreference",
"loc.input.help.progressPreference": "When not `Default`, prepends the line `$ProgressPreference = 'VALUE'` at the top of your script.",
"loc.input.label.failOnStderr": "Fail on Standard Error",
"loc.input.help.failOnStderr": "If this is true, this task will fail if any errors are written to the error pipeline, or if any data is written to the Standard Error stream. Otherwise the task will rely on the exit code to determine failure.",
"loc.input.label.showWarnings": "Show warnings as Azure DevOps warnings",
Expand Down
8 changes: 4 additions & 4 deletions Tasks/PowerShellV2/Tests/L0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('PowerShell Suite', function () {
runValidations(() => {
assert(tr.succeeded, 'PowerShell should have succeeded.');
assert(tr.stderr.length === 0, 'PowerShell should not have written to stderr');
assert(tr.stdout.indexOf(`Writing \ufeff$ErrorActionPreference = 'Stop'${os.EOL}Write-Host "my script output" to temp/path/fileName.ps1`) > 0, 'PowerShell should have written the script to a file');
assert(tr.stdout.indexOf(`Writing \ufeff$ErrorActionPreference = 'Stop'${os.EOL}$ProgressPreference = 'SilentlyContinue'${os.EOL}Write-Host "my script output" to temp/path/fileName.ps1`) > 0, 'PowerShell should have written the script to a file');
assert(tr.stdout.indexOf('my script output') > 0,'PowerShell should have correctly run the script');
}, tr, done);
});
Expand All @@ -45,7 +45,7 @@ describe('PowerShell Suite', function () {
runValidations(() => {
assert(tr.succeeded, 'PowerShell should have succeeded.');
assert(tr.stderr.length === 0, 'PowerShell should not have written to stderr');
assert(tr.stdout.indexOf(`Writing \ufeff$ErrorActionPreference = 'Stop'${os.EOL}. 'path/to/script.ps1' to temp/path/fileName.ps1`) > 0, 'PowerShell should have written the script to a file');
assert(tr.stdout.indexOf(`Writing \ufeff$ErrorActionPreference = 'Stop'${os.EOL}$ProgressPreference = 'SilentlyContinue'${os.EOL}. 'path/to/script.ps1' to temp/path/fileName.ps1`) > 0, 'PowerShell should have written the script to a file');
assert(tr.stdout.indexOf('my script output') > 0,'PowerShell should have correctly run the script');
}, tr, done);
});
Expand All @@ -61,7 +61,7 @@ describe('PowerShell Suite', function () {
runValidations(() => {
assert(tr.succeeded, 'PowerShell should have succeeded.');
assert(tr.stderr.length === 0, 'PowerShell should not have written to stderr');
assert(tr.stdout.indexOf(`Writing \ufeff$ErrorActionPreference = 'Stop'${os.EOL}. 'path/to/script.ps1' myCustomArg to temp/path/fileName.ps1`) > 0, 'PowerShell should have written the script to a file');
assert(tr.stdout.indexOf(`Writing \ufeff$ErrorActionPreference = 'Stop'${os.EOL}$ProgressPreference = 'SilentlyContinue'${os.EOL}. 'path/to/script.ps1' myCustomArg to temp/path/fileName.ps1`) > 0, 'PowerShell should have written the script to a file');
assert(tr.stdout.indexOf('my script output') > 0,'PowerShell should have correctly run the script');
}, tr, done);
});
Expand Down Expand Up @@ -92,7 +92,7 @@ describe('PowerShell Suite', function () {
runValidations(() => {
assert(tr.succeeded, 'PowerShell should have succeeded.');
assert(tr.stderr.length === 0, 'PowerShell should not have written to stderr');
assert(tr.stdout.indexOf(`Writing \ufeff$ErrorActionPreference = 'Stop'${os.EOL}. 'path/to/script.ps1' to temp/path/fileName.ps1`) > 0, 'PowerShell should have written the script to a file');
assert(tr.stdout.indexOf(`Writing \ufeff$ErrorActionPreference = 'Stop'${os.EOL}$ProgressPreference = 'SilentlyContinue'${os.EOL}. 'path/to/script.ps1' to temp/path/fileName.ps1`) > 0, 'PowerShell should have written the script to a file');
assert(tr.stdout.indexOf('my script output') > 0,'PowerShell should have correctly run the script');
}, tr, done);
});
Expand Down
4 changes: 4 additions & 0 deletions Tasks/PowerShellV2/powershell.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ try {
$input_informationPreference = Get-ActionPreference -VstsInputName 'informationPreference' -DefaultAction 'Default'
$input_verbosePreference = Get-ActionPreference -VstsInputName 'verbosePreference' -DefaultAction 'Default'
$input_debugPreference = Get-ActionPreference -VstsInputName 'debugPreference' -DefaultAction 'Default'
$input_progressPreference = Get-ActionPreference -VstsInputName 'progressPreference' -DefaultAction 'SilentlyContinue'

$input_showWarnings = Get-VstsInput -Name 'showWarnings' -AsBool
$input_failOnStderr = Get-VstsInput -Name 'failOnStderr' -AsBool
Expand Down Expand Up @@ -84,6 +85,9 @@ try {
if ($input_debugPreference -ne 'Default') {
$contents += "`$DebugPreference = '$input_debugPreference'"
}
if ($input_progressPreference -ne 'Default') {
$contents += "`$ProgressPreference = '$input_progressPreference'"
}
# Change default error view to normal view. We need this for error handling since we pipe stdout and stderr to the same stream
# and we rely on PowerShell piping back NormalView error records (required because PowerShell Core changed the default to ConciseView)
$contents += "`$ErrorView = 'NormalView'"
Expand Down
6 changes: 6 additions & 0 deletions Tasks/PowerShellV2/powershell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ async function run() {
let input_informationPreference: string = getActionPreference('informationPreference', 'Default');
let input_verbosePreference: string = getActionPreference('verbosePreference', 'Default');
let input_debugPreference: string = getActionPreference('debugPreference', 'Default');
let input_progressPreference: string = getActionPreference('progressPreference', 'SilentlyContinue');

let input_showWarnings = tl.getBoolInput('showWarnings', false);
let input_failOnStderr = tl.getBoolInput('failOnStderr', false);
let input_ignoreLASTEXITCODE = tl.getBoolInput('ignoreLASTEXITCODE', false);
Expand Down Expand Up @@ -67,6 +69,10 @@ async function run() {
if (input_debugPreference.toUpperCase() != 'DEFAULT') {
contents.push(`$DebugPreference = '${input_debugPreference}'`);
}
if (input_progressPreference.toUpperCase() != 'DEFAULT') {
contents.push(`$ProgressPreference = '${input_progressPreference}'`);
}

let script = '';
if (input_targetType.toUpperCase() == 'FILEPATH') {
script = `. '${input_filePath.replace(/'/g, "''")}' ${input_arguments}`.trim();
Expand Down
17 changes: 16 additions & 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": 200,
"Minor": 210,
"Patch": 0
},
"releaseNotes": "Script task consistency. Added support for macOS and Linux.",
Expand Down Expand Up @@ -155,6 +155,21 @@
"helpMarkDown": "When not `Default`, prepends the line `$DebugPreference = 'VALUE'` at the top of your script.",
"groupName": "preferenceVariables"
},
{
"name": "progressPreference",
"type": "pickList",
"label": "ProgressPreference",
"required": false,
"defaultValue": "silentlyContinue",
"options": {
"default": "Default",
"stop": "Stop",
"continue": "Continue",
"silentlyContinue": "SilentlyContinue"
},
"helpMarkDown": "When not `Default`, prepends the line `$ProgressPreference = 'VALUE'` at the top of your script.",
"groupName": "preferenceVariables"
},
{
"name": "failOnStderr",
"type": "boolean",
Expand Down
17 changes: 16 additions & 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": 200,
"Minor": 210,
"Patch": 0
},
"releaseNotes": "ms-resource:loc.releaseNotes",
Expand Down Expand Up @@ -155,6 +155,21 @@
"helpMarkDown": "ms-resource:loc.input.help.debugPreference",
"groupName": "preferenceVariables"
},
{
"name": "progressPreference",
"type": "pickList",
"label": "ms-resource:loc.input.label.progressPreference",
"required": false,
"defaultValue": "silentlyContinue",
"options": {
"default": "Default",
"stop": "Stop",
"continue": "Continue",
"silentlyContinue": "SilentlyContinue"
},
"helpMarkDown": "ms-resource:loc.input.help.progressPreference",
"groupName": "preferenceVariables"
},
{
"name": "failOnStderr",
"type": "boolean",
Expand Down

0 comments on commit 71408f9

Please sign in to comment.