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

PowerShell task should configure logging streams #15069

Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
5f13f83
PowerShell task should configure logging streams
Jul 16, 2021
458fc7c
Bump task version
Jul 16, 2021
ff6ab60
Update tests
Jul 22, 2021
597db45
Merge branch 'master' into dev/bradwhit/PowerShell/ConfigureLoggingSt…
Jul 22, 2021
9f7ad2c
Merge branch 'master' into dev/bradwhit/PowerShell/ConfigureLoggingSt…
EzzhevNikita Jul 26, 2021
d55ddc9
Forgot to add VerbosePreference to tests
Jul 26, 2021
6118b9f
Addressing feedback
Aug 4, 2021
2b427d9
Merge branch 'master' into dev/bradwhit/PowerShell/ConfigureLoggingSt…
bradselw Aug 4, 2021
42edd28
Make preferences adjustable via task inputs
Aug 9, 2021
90faa32
Merge branch 'master' into dev/bradwhit/PowerShell/ConfigureLoggingSt…
bradselw Aug 9, 2021
f06ab26
Merge branch 'master' into dev/bradwhit/PowerShell/ConfigureLoggingSt…
Aug 10, 2021
b03d6ca
Merge branch 'master' into dev/bradwhit/PowerShell/ConfigureLoggingSt…
bradselw Aug 13, 2021
333891a
Address PR feedback
Aug 13, 2021
3362421
Trying to fix resource files
Aug 13, 2021
3960fb8
Address feedback
Sep 13, 2021
550f001
Update sprint version
Sep 13, 2021
f335670
Merge branch 'master' into dev/bradwhit/PowerShell/ConfigureLoggingSt…
Sep 13, 2021
37c81dc
Fix tests
Sep 13, 2021
f3d4a3e
Merge branch 'master' into dev/bradwhit/PowerShell/ConfigureLoggingSt…
Sep 14, 2021
0332bc8
Merge branch 'master' into dev/bradwhit/PowerShell/ConfigureLoggingSt…
Sep 16, 2021
9db79a6
Bump to version 2.194.0
Sep 16, 2021
05614fa
Merge branch 'master' into dev/bradwhit/PowerShell/ConfigureLoggingSt…
Sep 17, 2021
c80068f
Merge branch 'master' into dev/bradwhit/PowerShell/ConfigureLoggingSt…
bradselw Sep 20, 2021
1fe909e
Merge branch 'master' into dev/bradwhit/PowerShell/ConfigureLoggingSt…
Sep 21, 2021
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
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$VerbosePreference = 'SilentlyContinue'${os.EOL}$InformationPreference = 'Continue'${os.EOL}$WarningPreference = 'Continue'${os.EOL}$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('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$VerbosePreference = 'SilentlyContinue'${os.EOL}$InformationPreference = 'Continue'${os.EOL}$WarningPreference = 'Continue'${os.EOL}$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('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$VerbosePreference = 'SilentlyContinue'${os.EOL}$InformationPreference = 'Continue'${os.EOL}$WarningPreference = 'Continue'${os.EOL}$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('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$VerbosePreference = 'SilentlyContinue'${os.EOL}$InformationPreference = 'Continue'${os.EOL}$WarningPreference = 'Continue'${os.EOL}$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('my script output') > 0,'PowerShell should have correctly run the script');
}, tr, done);
});
Expand Down
11 changes: 11 additions & 0 deletions Tasks/PowerShellV2/powershell.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,18 @@ try {
# Generate the script contents.
Write-Host (Get-VstsLocString -Key 'GeneratingScript')
$contents = @()

# Explicitly set the default output stream preferences, rather then relying on PowerShell's defaults.
if ($env:system_debug -eq "true") {
$contents += "`$VerbosePreference = 'Continue'"
}
else {
$contents += "`$VerbosePreference = 'SilentlyContinue'"
}
$contents += "`$InformationPreference = 'Continue'"
$contents += "`$WarningPreference = 'Continue'"
$contents += "`$ErrorActionPreference = '$input_errorActionPreference'"

# 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
10 changes: 10 additions & 0 deletions Tasks/PowerShellV2/powershell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,17 @@ async function run() {
// Generate the script contents.
console.log(tl.loc('GeneratingScript'));
let contents: string[] = [];

// Explicitly set the default output stream preferences, rather then relying on PowerShell's defaults.
if ((process.env['SYSTEM_DEBUG'] || "").toLowerCase() === "true") {
contents.push(`$VerbosePreference = 'Continue'`);
} else {
contents.push(`$VerbosePreference = 'SilentlyContinue'`);
}
contents.push(`$InformationPreference = 'Continue'`);
contents.push(`$WarningPreference = 'Continue'`);
contents.push(`$ErrorActionPreference = '${input_errorActionPreference}'`);

let script = '';
if (input_targetType.toUpperCase() == 'FILEPATH') {
script = `. '${input_filePath.replace(/'/g, "''")}' ${input_arguments}`.trim();
Expand Down
2 changes: 1 addition & 1 deletion Tasks/PowerShellV2/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"version": {
"Major": 2,
"Minor": 190,
"Patch": 0
"Patch": 1
},
"releaseNotes": "Script task consistency. Added support for macOS and Linux.",
"minimumAgentVersion": "2.115.0",
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 @@ -18,7 +18,7 @@
"version": {
"Major": 2,
"Minor": 190,
"Patch": 0
"Patch": 1
},
"releaseNotes": "ms-resource:loc.releaseNotes",
"minimumAgentVersion": "2.115.0",
Expand Down