From b2063b404ef4249b1fbad2a0d6817221fd75b736 Mon Sep 17 00:00:00 2001 From: akshaya Date: Thu, 16 Jan 2020 10:45:51 +0530 Subject: [PATCH 1/5] Added additional logs to identify script errors --- Tasks/AzurePowerShellV3/AzurePowerShell.ps1 | 40 ++++++++++++++++----- Tasks/AzurePowerShellV3/task.json | 2 +- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/Tasks/AzurePowerShellV3/AzurePowerShell.ps1 b/Tasks/AzurePowerShellV3/AzurePowerShell.ps1 index 5c94ead22582..004aaea97bcf 100644 --- a/Tasks/AzurePowerShellV3/AzurePowerShell.ps1 +++ b/Tasks/AzurePowerShellV3/AzurePowerShell.ps1 @@ -11,6 +11,7 @@ $__vsts_input_failOnStandardError = Get-VstsInput -Name FailOnStandardError $targetAzurePs = Get-VstsInput -Name TargetAzurePs $customTargetAzurePs = Get-VstsInput -Name CustomTargetAzurePs +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") { @@ -18,11 +19,11 @@ if ($scriptType -eq "FilePath") { throw (Get-VstsLocString -Key InvalidScriptPath0 -ArgumentList $scriptPath) } } - + if ($scriptArguments -match '[\r\n]') { throw (Get-VstsLocString -Key InvalidScriptArguments0 -ArgumentList $scriptArguments) } - + # string constants $otherVersion = "OtherVersion" $latestVersion = "LatestVersion" @@ -34,16 +35,18 @@ if ($targetAzurePs -eq $otherVersion) { $targetAzurePs = $customTargetAzurePs.Trim() } } - + $pattern = "^[0-9]+\.[0-9]+\.[0-9]+$" $regex = New-Object -TypeName System.Text.RegularExpressions.Regex -ArgumentList $pattern - + if ($targetAzurePs -eq $latestVersion) { $targetAzurePs = "" } 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" $targetAzurePs = Get-RollForwardVersion -azurePowerShellVersion $targetAzurePs @@ -52,6 +55,7 @@ try { $serviceNameInput = Get-VstsInput -Name ConnectedServiceNameSelector -Default 'ConnectedServiceName' $serviceName = Get-VstsInput -Name $serviceNameInput -Default (Get-VstsInput -Name DeploymentEnvironmentName) + if (!$serviceName) { Get-VstsInput -Name $serviceNameInput -Require @@ -74,10 +78,27 @@ catch Update-PSModulePathForHostedAgent -targetAzurePs $targetAzurePs -authScheme $authScheme +# 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-Azure -azurePsVersion $targetAzurePs -strict + 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 { # Trace the expression as it will be invoked. $__vstsAzPSInlineScriptPath = $null If ($scriptType -eq "InlineScript") { @@ -150,13 +171,14 @@ try { ,$_ } } -} +} finally { if ($__vstsAzPSInlineScriptPath -and (Test-Path -LiteralPath $__vstsAzPSInlineScriptPath) ) { Remove-Item -LiteralPath $__vstsAzPSInlineScriptPath -ErrorAction 'SilentlyContinue' } +} +Write-Host "## Stage 3: Running script Complete" - Import-Module $PSScriptRoot\ps_modules\VstsAzureHelpers_ - Remove-EndpointSecrets - Disconnect-AzureAndClearContext -authScheme $authScheme -ErrorAction SilentlyContinue -} \ No newline at end of file +Import-Module $PSScriptRoot\ps_modules\VstsAzureHelpers_ +Remove-EndpointSecrets +Disconnect-AzureAndClearContext -authScheme $authScheme -ErrorAction SilentlyContinue diff --git a/Tasks/AzurePowerShellV3/task.json b/Tasks/AzurePowerShellV3/task.json index 1d0d46a4c85c..ec9308e18b7b 100644 --- a/Tasks/AzurePowerShellV3/task.json +++ b/Tasks/AzurePowerShellV3/task.json @@ -18,7 +18,7 @@ "version": { "Major": 3, "Minor": 153, - "Patch": 2 + "Patch": 3 }, "releaseNotes": "Added support for Fail on standard error and ErrorActionPreference", "demands": [ From 2f0a83382084a388e4a7a4b98b22feb4d1b9b2f8 Mon Sep 17 00:00:00 2001 From: akshaya Date: Thu, 16 Jan 2020 14:17:35 +0530 Subject: [PATCH 2/5] Added task.loc.json --- Tasks/AzurePowerShellV3/task.loc.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tasks/AzurePowerShellV3/task.loc.json b/Tasks/AzurePowerShellV3/task.loc.json index ec58e2734982..f92cfe1ac85e 100644 --- a/Tasks/AzurePowerShellV3/task.loc.json +++ b/Tasks/AzurePowerShellV3/task.loc.json @@ -18,7 +18,7 @@ "version": { "Major": 3, "Minor": 153, - "Patch": 2 + "Patch": 3 }, "releaseNotes": "ms-resource:loc.releaseNotes", "demands": [ From 343e5a8c7d29bd86e6d802b3756e8c1998982290 Mon Sep 17 00:00:00 2001 From: akshaya1509 Date: Fri, 24 Jan 2020 13:15:06 +0530 Subject: [PATCH 3/5] Added changes for review comments --- Tasks/AzurePowerShellV3/AzurePowerShell.ps1 | 24 +++++++++------------ 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/Tasks/AzurePowerShellV3/AzurePowerShell.ps1 b/Tasks/AzurePowerShellV3/AzurePowerShell.ps1 index 004aaea97bcf..298126475c1b 100644 --- a/Tasks/AzurePowerShellV3/AzurePowerShell.ps1 +++ b/Tasks/AzurePowerShellV3/AzurePowerShell.ps1 @@ -11,7 +11,7 @@ $__vsts_input_failOnStandardError = Get-VstsInput -Name FailOnStandardError $targetAzurePs = Get-VstsInput -Name TargetAzurePs $customTargetAzurePs = Get-VstsInput -Name CustomTargetAzurePs -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") { @@ -44,9 +44,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" $targetAzurePs = Get-RollForwardVersion -azurePowerShellVersion $targetAzurePs @@ -79,25 +79,21 @@ catch Update-PSModulePathForHostedAgent -targetAzurePs $targetAzurePs -authScheme $authScheme # 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-Azure -azurePsVersion $targetAzurePs -strict - 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 { # Trace the expression as it will be invoked. $__vstsAzPSInlineScriptPath = $null @@ -177,7 +173,7 @@ finally { Remove-Item -LiteralPath $__vstsAzPSInlineScriptPath -ErrorAction 'SilentlyContinue' } } -Write-Host "## Stage 3: Running script Complete" +Write-Host "## Running script Complete" Import-Module $PSScriptRoot\ps_modules\VstsAzureHelpers_ Remove-EndpointSecrets From 984a3d0339378e26eaf6f98ae6c7a73681ccf6f5 Mon Sep 17 00:00:00 2001 From: akshaya1509 Date: Thu, 30 Jan 2020 10:01:33 +0530 Subject: [PATCH 4/5] Added troubleshoot fwd link --- Tasks/AzurePowerShellV3/AzurePowerShell.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tasks/AzurePowerShellV3/AzurePowerShell.ps1 b/Tasks/AzurePowerShellV3/AzurePowerShell.ps1 index 298126475c1b..f6b0430b76fc 100644 --- a/Tasks/AzurePowerShellV3/AzurePowerShell.ps1 +++ b/Tasks/AzurePowerShellV3/AzurePowerShell.ps1 @@ -79,7 +79,7 @@ catch Update-PSModulePathForHostedAgent -targetAzurePs $targetAzurePs -authScheme $authScheme # troubleshoot link -$troubleshoot = "https://aka.ms/azure-powershell-troubleshoot" +$troubleshoot = "https://aka.ms/azurepowershelltroubleshooting" try { # Initialize Azure. Import-Module $PSScriptRoot\ps_modules\VstsAzureHelpers_ From abb4c8cb9a591b6c7d1f79793819981a214ef522 Mon Sep 17 00:00:00 2001 From: akshaya1509 Date: Mon, 3 Feb 2020 13:39:53 +0530 Subject: [PATCH 5/5] Added review comments --- Tasks/AzurePowerShellV3/AzurePowerShell.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tasks/AzurePowerShellV3/AzurePowerShell.ps1 b/Tasks/AzurePowerShellV3/AzurePowerShell.ps1 index f6b0430b76fc..4c3beba43026 100644 --- a/Tasks/AzurePowerShellV3/AzurePowerShell.ps1 +++ b/Tasks/AzurePowerShellV3/AzurePowerShell.ps1 @@ -93,7 +93,7 @@ finally { } } -Write-Host "## Running script" +Write-Host "## Beginning Script Execution" try { # Trace the expression as it will be invoked. $__vstsAzPSInlineScriptPath = $null @@ -173,7 +173,7 @@ finally { Remove-Item -LiteralPath $__vstsAzPSInlineScriptPath -ErrorAction 'SilentlyContinue' } } -Write-Host "## Running script Complete" +Write-Host "## Script Execution Complete" Import-Module $PSScriptRoot\ps_modules\VstsAzureHelpers_ Remove-EndpointSecrets