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 #12159

Merged
merged 6 commits into from
Feb 3, 2020
Merged
Show file tree
Hide file tree
Changes from 5 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
36 changes: 27 additions & 9 deletions Tasks/AzurePowerShellV3/AzurePowerShell.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,19 @@ $__vsts_input_failOnStandardError = Get-VstsInput -Name FailOnStandardError
$targetAzurePs = Get-VstsInput -Name TargetAzurePs
$customTargetAzurePs = Get-VstsInput -Name CustomTargetAzurePs

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") {
if ($scriptPath -match '[\r\n]' -or [string]::IsNullOrWhitespace($scriptPath)) {
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"
Expand All @@ -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 "## Validating Inputs Complete"

Write-Host "## Initializing Azure"
. "$PSScriptRoot\Utility.ps1"
$targetAzurePs = Get-RollForwardVersion -azurePowerShellVersion $targetAzurePs

Expand All @@ -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
Expand All @@ -74,10 +78,23 @@ catch

Update-PSModulePathForHostedAgent -targetAzurePs $targetAzurePs -authScheme $authScheme

# troubleshoot link
$troubleshoot = "https://aka.ms/azurepowershelltroubleshooting"
try {
# Initialize Azure.
Import-Module $PSScriptRoot\ps_modules\VstsAzureHelpers_
Initialize-Azure -azurePsVersion $targetAzurePs -strict
Write-Host "## Initializing Azure Complete"
$success = $true
}
finally {
if (!$success) {
Write-VstsTaskError "Initialize Azure failed: For troubleshooting, refer: $troubleshoot"
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there should also be a message saying "Azure initialization complete"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have added this log "Write-Host "## Initializing Azure Complete"" after Initialize-Azure is completed

}

Write-Host "## Beginning Script Execution"
try {
# Trace the expression as it will be invoked.
$__vstsAzPSInlineScriptPath = $null
If ($scriptType -eq "InlineScript") {
Expand Down Expand Up @@ -150,13 +167,14 @@ try {
,$_
}
}
}
}
finally {
if ($__vstsAzPSInlineScriptPath -and (Test-Path -LiteralPath $__vstsAzPSInlineScriptPath) ) {
Remove-Item -LiteralPath $__vstsAzPSInlineScriptPath -ErrorAction 'SilentlyContinue'
}
}
Write-Host "## Script Execution Complete"

Import-Module $PSScriptRoot\ps_modules\VstsAzureHelpers_
Remove-EndpointSecrets
Disconnect-AzureAndClearContext -authScheme $authScheme -ErrorAction SilentlyContinue
}
Import-Module $PSScriptRoot\ps_modules\VstsAzureHelpers_
Remove-EndpointSecrets
Disconnect-AzureAndClearContext -authScheme $authScheme -ErrorAction SilentlyContinue
2 changes: 1 addition & 1 deletion Tasks/AzurePowerShellV3/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"version": {
"Major": 3,
"Minor": 153,
"Patch": 2
"Patch": 3
},
"releaseNotes": "Added support for Fail on standard error and ErrorActionPreference",
"demands": [
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzurePowerShellV3/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"version": {
"Major": 3,
"Minor": 153,
"Patch": 2
"Patch": 3
},
"releaseNotes": "ms-resource:loc.releaseNotes",
"demands": [
Expand Down