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

Added additional logs to identify script errors in AzurePowerShellV4 #12167

Merged
merged 7 commits into from
Feb 4, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
20 changes: 18 additions & 2 deletions Tasks/AzurePowerShellV4/AzurePowerShell.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ $customTargetAzurePs = Get-VstsInput -Name CustomTargetAzurePs
$input_pwsh = Get-VstsInput -Name pwsh -AsBool
$input_workingDirectory = Get-VstsInput -Name workingDirectory -Require

Write-Host "## Validating Inputs"
# Validate the script path and args do not contains new-lines. Otherwise, it will
# break invoking the script via Invoke-Expression.
if ($scriptType -eq "FilePath") {
Expand Down Expand Up @@ -45,20 +46,34 @@ if ($targetAzurePs -eq $latestVersion) {
} elseif (-not($regex.IsMatch($targetAzurePs))) {
throw (Get-VstsLocString -Key InvalidAzurePsVersion -ArgumentList $targetAzurePs)
}
Write-Host "## Validating Inputs Complete"

Write-Host "## Initializing Az module"
. "$PSScriptRoot\Utility.ps1"

$serviceName = Get-VstsInput -Name ConnectedServiceNameARM -Require
$endpoint = Get-VstsEndpoint -Name $serviceName -Require
CleanUp-PSModulePathForHostedAgent
Update-PSModulePathForHostedAgent -targetAzurePs $targetAzurePs

# troubleshoot link
$troubleshoot = "https://aka.ms/azurepowershelltroubleshooting"
try
{
# Initialize Azure.
Import-Module $PSScriptRoot\ps_modules\VstsAzureHelpers_
Initialize-AzModule -Endpoint $endpoint -azVersion $targetAzurePs

Write-Host "## Az module initialization Complete"
$success = $true
}
finally {
if (!$success) {
Write-VstsTaskError "Initializing Az module failed: For troubleshooting, refer: $troubleshoot"
}
}

Write-Host "## Beginning Script Execution"
try {
if ($input_pwsh)
{
# Generate the script contents.
Expand Down Expand Up @@ -247,4 +262,5 @@ finally {
Import-Module $PSScriptRoot\ps_modules\VstsAzureHelpers_
Remove-EndpointSecrets
Disconnect-AzureAndClearContext -ErrorAction SilentlyContinue
}
}
Write-Host "## Script Execution Complete"
9 changes: 9 additions & 0 deletions Tasks/AzurePowerShellV4/azurepowershell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ async function run() {
tl.setResourcePath(path.join(__dirname, 'task.json'));

// Get inputs.
console.log("## Validating Inputs");
let _vsts_input_errorActionPreference: string = tl.getInput('errorActionPreference', false) || 'Stop';
switch (_vsts_input_errorActionPreference.toUpperCase()) {
case 'STOP':
Expand Down Expand Up @@ -54,8 +55,10 @@ async function run() {
throw new Error(tl.loc('JS_InvalidFilePath', scriptPath));
}
}
console.log("## Validating Inputs Complete");

// Generate the script contents.
console.log("## Initializing Az module");
console.log(tl.loc('GeneratingScript'));
let contents: string[] = [];
let azFilePath = path.join(path.resolve(__dirname), 'InitializeAz.ps1');
Expand Down Expand Up @@ -86,7 +89,9 @@ async function run() {
'\ufeff' + contents.join(os.EOL), // Prepend the Unicode BOM character.
{ encoding: 'utf8' }); // Since UTF8 encoding is specified, node will
// encode the BOM into its UTF8 binary sequence.
console.log("## Az module initialization Complete");

console.log("## Beginning Script Execution");
// Run the script.
//
// Note, prefer "pwsh" over "powershell". At some point we can remove support for "powershell".
Expand Down Expand Up @@ -130,8 +135,12 @@ async function run() {
if (stderrFailure) {
tl.setResult(tl.TaskResult.Failed, tl.loc('JS_Stderr'));
}
console.log("## Script Execution Complete");
}
catch (err) {
// troubleshoot link
const troubleshoot = "https://aka.ms/azurepowershelltroubleshooting";
console.log(`##[error] run failed: For troubleshooting, refer: ${troubleshoot}`);
tl.setResult(tl.TaskResult.Failed, err.message || 'run() failed');
}
}
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzurePowerShellV4/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"version": {
"Major": 4,
"Minor": 159,
"Patch": 11
"Patch": 12
},
"releaseNotes": "Added support for Az Module and cross platform agents.",
"groups": [
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzurePowerShellV4/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"version": {
"Major": 4,
"Minor": 159,
"Patch": 11
"Patch": 12
},
"releaseNotes": "ms-resource:loc.releaseNotes",
"groups": [
Expand Down