[devops] Append to the agent log, instead of creating the file. (#21281)

Append to the agent log, instead of creating the file, when an exception occcurs.

The problem is that creating the file fails if it already exists:

    Exception occurred: Exception calling "Parse" with "1" argument(s): "String '' was not recognized as a valid DateTime."
    New-Item: /Users/builder/azdo/_work/4/s/xamarin-macios/tools/devops/automation/scripts/generate_agent_logs.ps1:52
    Line |
      52 |      New-Item -Path $Output -Value "$_"
         |      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         | The file '/Users/builder/azdo/_work/4/s/agent-logs.log' already exists.
This commit is contained in:
Rolf Bjarne Kvinge 2024-09-20 17:44:57 +02:00 коммит произвёл GitHub
Родитель ba954b9c24
Коммит 16a6284e58
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
1 изменённых файлов: 1 добавлений и 2 удалений

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

@ -46,8 +46,7 @@ try {
log show --predicate $Predicate --style $Style --start "$start" --end "$end" > $Output
}
} catch {
Write-Host "Exception occurred: $_"
# Create the output file, because we later try to upload it as an artifact, and *not* uploading
# if there's *no* file is much harder than just creating the file.
New-Item -Path $Output -Value "$_"
Write-Host "Exception occurred: $_" | Tee-Object -FilePath $Output -Append
}