[CI] Allow to retrieve the logs of the agent. (#13662)

This commit is contained in:
Manuel de la Pena 2022-01-10 17:07:43 -05:00 коммит произвёл GitHub
Родитель 94863148dc
Коммит 345f7a367e
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 75 добавлений и 0 удалений

Просмотреть файл

@ -572,3 +572,7 @@ steps:
artifactName: all-binlogs
continueOnError: true
condition: succeededOrFailed()
- template: ../common/mac-agent-logs.yml
parameters:
outputPath: agent-logs.log

Просмотреть файл

@ -0,0 +1,71 @@
# This template will gather all the logs of a mac agent from a given starting poing in time
# to a given end point. The template also takes the path for the file where the logs will be written.
#
parameters:
- name: workingDirectory
type: string
default: ''
- name: outputPath
type: string
default: ''
- name: predicate
type: string
default: ''
- name: style
type: string
default: 'compact'
values:
- default
- compact
- json
- syslog
steps:
- pwsh: |
$style=$Env:STYLE
$output=$Env:OUTPUT
if (-not $output) {
Write-Host "Not output path provided using default path: agent-logs.log"
$output="agent-logs.log"
} else {
Write-Host "output path: $output"
}
# there is no var that gives us the start time, but we can use the rest api to get the time when
# the build started
# User name can be anything. It is the personal access token (PAT) token that matters.
$user= "AnyUser"
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user, $Env:ACCESSTOKEN)))
$headers = @{Authorization = "Basic {0}" -f $base64AuthInfo}
# get the url of the build
$url= $Env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI + "$Env:SYSTEM_TEAMPROJECT/_apis/build/builds/" + $Env:BUILD_BUILDID + "?api-version=5.1"
$buildPipeline= Invoke-RestMethod -Uri $url -Headers $headers -Method Get
$start=[DateTime]::Parse($buildPipeline.startTime).ToString("yyyy-MM-dd HH:mm:ss")
$end=Get-Date -Format "yyyy-mm-dd HH:mm:ss"
Write-Host "end time: $end"
$predicate=$Env:PREDICATE
if (-not $predicate) {
log show --style $style --start "$start" --end "$end" > $output
} else {
log show --predicate $predicate --style $style --start "$start" --end "$end" > $output
}
displayName: 'Gathering agent logs'
env:
ACCESSTOKEN: $(System.AccessToken)
OUTPUT: ${{ parameters.outputPath }}
PREDICATE: ${{ parameters.predicate }}
STYLE: ${{ parameters.style }}
${{ if ne(parameters.workingDirectory, '') }}:
workingDirectory: ${{ parameters.workingDirectory }}