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 1 commit
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
24 changes: 22 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 "## 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") {
Expand Down Expand Up @@ -45,20 +46,38 @@ 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
$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.
Expand Down Expand Up @@ -247,4 +266,5 @@ finally {
Import-Module $PSScriptRoot\ps_modules\VstsAzureHelpers_
Remove-EndpointSecrets
Disconnect-AzureAndClearContext -ErrorAction SilentlyContinue
}
}
Write-Host "## Stage 3: Running script Complete"
Copy link
Contributor

Choose a reason for hiding this comment

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

Write these logs even in azurepowershell.ts file as it is for linux

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