From 16a6284e589d748b051188283a40bd38d5c24886 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Fri, 20 Sep 2024 17:44:57 +0200 Subject: [PATCH] [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. --- tools/devops/automation/scripts/generate_agent_logs.ps1 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tools/devops/automation/scripts/generate_agent_logs.ps1 b/tools/devops/automation/scripts/generate_agent_logs.ps1 index 089a65511e..3294e9138c 100644 --- a/tools/devops/automation/scripts/generate_agent_logs.ps1 +++ b/tools/devops/automation/scripts/generate_agent_logs.ps1 @@ -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 }