From 97a6183dd7eefb636573ae94b3fc7f04c79f9e6c Mon Sep 17 00:00:00 2001 From: akshaya Date: Fri, 17 Jan 2020 11:59:08 +0530 Subject: [PATCH 1/6] Added additional logs to identify script errors --- Tasks/AzurePowerShellV4/AzurePowerShell.ps1 | 24 +++++++++++++++++++-- Tasks/AzurePowerShellV4/task.json | 2 +- Tasks/AzurePowerShellV4/task.loc.json | 2 +- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/Tasks/AzurePowerShellV4/AzurePowerShell.ps1 b/Tasks/AzurePowerShellV4/AzurePowerShell.ps1 index 1a131dd3aa75..08ce818712db 100644 --- a/Tasks/AzurePowerShellV4/AzurePowerShell.ps1 +++ b/Tasks/AzurePowerShellV4/AzurePowerShell.ps1 @@ -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 "## Stage 1: Input Validation" # 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") { @@ -45,7 +46,9 @@ if ($targetAzurePs -eq $latestVersion) { } elseif (-not($regex.IsMatch($targetAzurePs))) { throw (Get-VstsLocString -Key InvalidAzurePsVersion -ArgumentList $targetAzurePs) } +Write-Host "## Stage 1: Input Validation Complete" +Write-Host "## Stage 2: Initialize Azure" . "$PSScriptRoot\Utility.ps1" $serviceName = Get-VstsInput -Name ConnectedServiceNameARM -Require @@ -53,12 +56,28 @@ $endpoint = Get-VstsEndpoint -Name $serviceName -Require CleanUp-PSModulePathForHostedAgent Update-PSModulePathForHostedAgent -targetAzurePs $targetAzurePs +# troubleshoot link +$troubleshoot = "https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/azure-powershell?view=azure-devops#troubleshooting" +$status = $true try { # Initialize Azure. Import-Module $PSScriptRoot\ps_modules\VstsAzureHelpers_ Initialize-AzModule -Endpoint $endpoint -azVersion $targetAzurePs - + Write-Host "## Stage 2: Initialize Azure Complete" +} +catch { + $status = $false + throw +} +finally { + if (!$status) { + Write-Host "## Initialize Azure failed: For troubleshooting, refer: $troubleshoot" + } +} + +Write-Host "## Stage 3: Running script" +try { if ($input_pwsh) { # Generate the script contents. @@ -247,4 +266,5 @@ finally { Import-Module $PSScriptRoot\ps_modules\VstsAzureHelpers_ Remove-EndpointSecrets Disconnect-AzureAndClearContext -ErrorAction SilentlyContinue -} \ No newline at end of file +} +Write-Host "## Stage 3: Running script Complete" \ No newline at end of file diff --git a/Tasks/AzurePowerShellV4/task.json b/Tasks/AzurePowerShellV4/task.json index 1090cab719fa..43799984d473 100644 --- a/Tasks/AzurePowerShellV4/task.json +++ b/Tasks/AzurePowerShellV4/task.json @@ -17,7 +17,7 @@ "version": { "Major": 4, "Minor": 159, - "Patch": 11 + "Patch": 12 }, "releaseNotes": "Added support for Az Module and cross platform agents.", "groups": [ diff --git a/Tasks/AzurePowerShellV4/task.loc.json b/Tasks/AzurePowerShellV4/task.loc.json index 7588ae525e94..a1183f8a310b 100644 --- a/Tasks/AzurePowerShellV4/task.loc.json +++ b/Tasks/AzurePowerShellV4/task.loc.json @@ -17,7 +17,7 @@ "version": { "Major": 4, "Minor": 159, - "Patch": 11 + "Patch": 12 }, "releaseNotes": "ms-resource:loc.releaseNotes", "groups": [ From d1c3491f7627997778c34b60d39c28f979adeec3 Mon Sep 17 00:00:00 2001 From: akshaya1509 Date: Mon, 27 Jan 2020 11:43:26 +0530 Subject: [PATCH 2/6] Added review comments --- Tasks/AzurePowerShellV4/AzurePowerShell.ps1 | 24 +++++++++------------ 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/Tasks/AzurePowerShellV4/AzurePowerShell.ps1 b/Tasks/AzurePowerShellV4/AzurePowerShell.ps1 index 08ce818712db..8d0031d73238 100644 --- a/Tasks/AzurePowerShellV4/AzurePowerShell.ps1 +++ b/Tasks/AzurePowerShellV4/AzurePowerShell.ps1 @@ -13,7 +13,7 @@ $customTargetAzurePs = Get-VstsInput -Name CustomTargetAzurePs $input_pwsh = Get-VstsInput -Name pwsh -AsBool $input_workingDirectory = Get-VstsInput -Name workingDirectory -Require -Write-Host "## Stage 1: Input Validation" +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") { @@ -46,9 +46,9 @@ if ($targetAzurePs -eq $latestVersion) { } elseif (-not($regex.IsMatch($targetAzurePs))) { throw (Get-VstsLocString -Key InvalidAzurePsVersion -ArgumentList $targetAzurePs) } -Write-Host "## Stage 1: Input Validation Complete" +Write-Host "## Validating Inputs Complete" -Write-Host "## Stage 2: Initialize Azure" +Write-Host "## Initializing Azure" . "$PSScriptRoot\Utility.ps1" $serviceName = Get-VstsInput -Name ConnectedServiceNameARM -Require @@ -57,26 +57,22 @@ CleanUp-PSModulePathForHostedAgent Update-PSModulePathForHostedAgent -targetAzurePs $targetAzurePs # troubleshoot link -$troubleshoot = "https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/azure-powershell?view=azure-devops#troubleshooting" -$status = $true +$troubleshoot = "https://aka.ms/azure-powershell-troubleshoot" try { # Initialize Azure. Import-Module $PSScriptRoot\ps_modules\VstsAzureHelpers_ Initialize-AzModule -Endpoint $endpoint -azVersion $targetAzurePs - Write-Host "## Stage 2: Initialize Azure Complete" -} -catch { - $status = $false - throw + Write-Host "## Initializing Azure Complete" + $success = $true } finally { - if (!$status) { - Write-Host "## Initialize Azure failed: For troubleshooting, refer: $troubleshoot" + if (!$success) { + Write-VstsTaskError "Initialize Azure failed: For troubleshooting, refer: $troubleshoot" } } -Write-Host "## Stage 3: Running script" +Write-Host "## Running script" try { if ($input_pwsh) { @@ -267,4 +263,4 @@ finally { Remove-EndpointSecrets Disconnect-AzureAndClearContext -ErrorAction SilentlyContinue } -Write-Host "## Stage 3: Running script Complete" \ No newline at end of file +Write-Host "## Running script Complete" \ No newline at end of file From 49d40dc3f9e1e448792b6505bc174a451911d0ab Mon Sep 17 00:00:00 2001 From: akshaya1509 Date: Fri, 31 Jan 2020 12:52:19 +0530 Subject: [PATCH 3/6] Added troubleshoot fwd link --- Tasks/AzurePowerShellV4/AzurePowerShell.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tasks/AzurePowerShellV4/AzurePowerShell.ps1 b/Tasks/AzurePowerShellV4/AzurePowerShell.ps1 index 8d0031d73238..d68e33d3bdce 100644 --- a/Tasks/AzurePowerShellV4/AzurePowerShell.ps1 +++ b/Tasks/AzurePowerShellV4/AzurePowerShell.ps1 @@ -57,7 +57,7 @@ CleanUp-PSModulePathForHostedAgent Update-PSModulePathForHostedAgent -targetAzurePs $targetAzurePs # troubleshoot link -$troubleshoot = "https://aka.ms/azure-powershell-troubleshoot" +$troubleshoot = "https://aka.ms/azurepowershelltroubleshooting" try { # Initialize Azure. From 052a13aa4b895cf656dee92261cafe52ffd71731 Mon Sep 17 00:00:00 2001 From: akshaya1509 Date: Mon, 3 Feb 2020 12:04:36 +0530 Subject: [PATCH 4/6] Added additional logs to debug in azurepowershell.ts --- Tasks/AzurePowerShellV4/azurepowershell.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Tasks/AzurePowerShellV4/azurepowershell.ts b/Tasks/AzurePowerShellV4/azurepowershell.ts index 18fdc091c4d8..548166250515 100644 --- a/Tasks/AzurePowerShellV4/azurepowershell.ts +++ b/Tasks/AzurePowerShellV4/azurepowershell.ts @@ -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': @@ -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 Azure"); console.log(tl.loc('GeneratingScript')); let contents: string[] = []; let azFilePath = path.join(path.resolve(__dirname), 'InitializeAz.ps1'); @@ -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("## Initializing Azure Complete"); + console.log("## Running script"); // Run the script. // // Note, prefer "pwsh" over "powershell". At some point we can remove support for "powershell". @@ -130,8 +135,12 @@ async function run() { if (stderrFailure) { tl.setResult(tl.TaskResult.Failed, tl.loc('JS_Stderr')); } + console.log("## Running script Complete"); } catch (err) { + // troubleshoot link + const troubleshoot = "https://aka.ms/azurepowershelltroubleshooting"; + console.log(`For troubleshooting, refer: ${troubleshoot}`); tl.setResult(tl.TaskResult.Failed, err.message || 'run() failed'); } } From 05a6586ee3682818d34fe20d9da858de0d29c6ba Mon Sep 17 00:00:00 2001 From: akshaya1509 Date: Mon, 3 Feb 2020 14:17:55 +0530 Subject: [PATCH 5/6] Added review comments --- Tasks/AzurePowerShellV4/AzurePowerShell.ps1 | 4 ++-- Tasks/AzurePowerShellV4/azurepowershell.ts | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Tasks/AzurePowerShellV4/AzurePowerShell.ps1 b/Tasks/AzurePowerShellV4/AzurePowerShell.ps1 index d68e33d3bdce..aa630abb44bd 100644 --- a/Tasks/AzurePowerShellV4/AzurePowerShell.ps1 +++ b/Tasks/AzurePowerShellV4/AzurePowerShell.ps1 @@ -72,7 +72,7 @@ finally { } } -Write-Host "## Running script" +Write-Host "## Beginning Script Execution" try { if ($input_pwsh) { @@ -263,4 +263,4 @@ finally { Remove-EndpointSecrets Disconnect-AzureAndClearContext -ErrorAction SilentlyContinue } -Write-Host "## Running script Complete" \ No newline at end of file +Write-Host "## Script Execution Complete" \ No newline at end of file diff --git a/Tasks/AzurePowerShellV4/azurepowershell.ts b/Tasks/AzurePowerShellV4/azurepowershell.ts index 548166250515..72fc69fac692 100644 --- a/Tasks/AzurePowerShellV4/azurepowershell.ts +++ b/Tasks/AzurePowerShellV4/azurepowershell.ts @@ -91,7 +91,7 @@ async function run() { // encode the BOM into its UTF8 binary sequence. console.log("## Initializing Azure Complete"); - console.log("## Running script"); + console.log("## Beginning Script Execution"); // Run the script. // // Note, prefer "pwsh" over "powershell". At some point we can remove support for "powershell". @@ -135,12 +135,12 @@ async function run() { if (stderrFailure) { tl.setResult(tl.TaskResult.Failed, tl.loc('JS_Stderr')); } - console.log("## Running script Complete"); + console.log("## Script Execution Complete"); } catch (err) { // troubleshoot link const troubleshoot = "https://aka.ms/azurepowershelltroubleshooting"; - console.log(`For troubleshooting, refer: ${troubleshoot}`); + console.log(`##[error] run failed: For troubleshooting, refer: ${troubleshoot}`); tl.setResult(tl.TaskResult.Failed, err.message || 'run() failed'); } } From 2bd1d51385c08281ec44dc6534593d542029cb65 Mon Sep 17 00:00:00 2001 From: aksm-ms <58936966+aksm-ms@users.noreply.github.com> Date: Tue, 4 Feb 2020 11:41:18 +0530 Subject: [PATCH 6/6] Added review comments --- Tasks/AzurePowerShellV4/AzurePowerShell.ps1 | 6 +++--- Tasks/AzurePowerShellV4/azurepowershell.ts | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Tasks/AzurePowerShellV4/AzurePowerShell.ps1 b/Tasks/AzurePowerShellV4/AzurePowerShell.ps1 index aa630abb44bd..1e3ae03af59c 100644 --- a/Tasks/AzurePowerShellV4/AzurePowerShell.ps1 +++ b/Tasks/AzurePowerShellV4/AzurePowerShell.ps1 @@ -48,7 +48,7 @@ if ($targetAzurePs -eq $latestVersion) { } Write-Host "## Validating Inputs Complete" -Write-Host "## Initializing Azure" +Write-Host "## Initializing Az module" . "$PSScriptRoot\Utility.ps1" $serviceName = Get-VstsInput -Name ConnectedServiceNameARM -Require @@ -63,12 +63,12 @@ try # Initialize Azure. Import-Module $PSScriptRoot\ps_modules\VstsAzureHelpers_ Initialize-AzModule -Endpoint $endpoint -azVersion $targetAzurePs - Write-Host "## Initializing Azure Complete" + Write-Host "## Az module initialization Complete" $success = $true } finally { if (!$success) { - Write-VstsTaskError "Initialize Azure failed: For troubleshooting, refer: $troubleshoot" + Write-VstsTaskError "Initializing Az module failed: For troubleshooting, refer: $troubleshoot" } } diff --git a/Tasks/AzurePowerShellV4/azurepowershell.ts b/Tasks/AzurePowerShellV4/azurepowershell.ts index 72fc69fac692..be1a771d71a0 100644 --- a/Tasks/AzurePowerShellV4/azurepowershell.ts +++ b/Tasks/AzurePowerShellV4/azurepowershell.ts @@ -58,7 +58,7 @@ async function run() { console.log("## Validating Inputs Complete"); // Generate the script contents. - console.log("## Initializing Azure"); + console.log("## Initializing Az module"); console.log(tl.loc('GeneratingScript')); let contents: string[] = []; let azFilePath = path.join(path.resolve(__dirname), 'InitializeAz.ps1'); @@ -89,7 +89,7 @@ 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("## Initializing Azure Complete"); + console.log("## Az module initialization Complete"); console.log("## Beginning Script Execution"); // Run the script.