From fb3638b7b05e4c68c08790125e4bd0f4be2e8bc1 Mon Sep 17 00:00:00 2001 From: James Crosswell Date: Mon, 12 Oct 2026 12:54:21 +1300 Subject: [PATCH] fix(msbuild): Don't fail the build when sentry-cli has no auth token PrepareSentryCLI probes with `sentry-cli info` and skips uploads and release creation when it fails. Since sentry-cli 2.30.0 that command prints `error: ...` when it has no token (or the API request fails), and MSBuild parsed that line as a build error despite IgnoreExitCode, so the build failed before the skip could take effect. Fixes #5704 Co-Authored-By: Claude Opus 5.5 --- integration-test/cli.Tests.ps1 | 33 +++++++++++++++++++++-- src/Sentry/buildTransitive/Sentry.targets | 7 ++--- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/integration-test/cli.Tests.ps1 b/integration-test/cli.Tests.ps1 index c142438576..31bd7c2533 100644 --- a/integration-test/cli.Tests.ps1 +++ b/integration-test/cli.Tests.ps1 @@ -71,7 +71,23 @@ Describe 'Console apps () - release creation' -ForEach @( chmod +x $cliStub } - function BuildWithSentryCLIStub([string[]] $properties, [string] $extraSource) + function NewSentryCLIStubFailingInfo([string] $cliError) + { + if ($IsWindows) + { + $stub = Join-Path $PSScriptRoot 'release-app' 'sentry-cli-failing.cmd' + "@echo %* >> `"$cliLog`"`n@if `"%1`"==`"info`" (echo $cliError 1>&2 & exit 1)" | Set-Content $stub + } + else + { + $stub = Join-Path $PSScriptRoot 'release-app' 'sentry-cli-failing.sh' + "#!/bin/sh`necho `"`$*`" >> `"$cliLog`"`nif [ `"`$1`" = info ]; then echo '$cliError' >&2; exit 1; fi" | Set-Content $stub + chmod +x $stub + } + $stub + } + + function BuildWithSentryCLIStub([string[]] $properties, [string] $extraSource, [string] $stub = $cliStub) { Remove-Item $cliLog -ErrorAction SilentlyContinue $extraSourcePath = Join-Path $PSScriptRoot 'release-app' 'Extra.cs' @@ -79,13 +95,16 @@ Describe 'Console apps () - release creation' -ForEach @( { $extraSource | Set-Content $extraSourcePath } + # Not /p:SentryCLI, because the targets can't clear a global property when the CLI isn't configured + $env:SentryCLI = $stub try { - $output = dotnet build release-app -c Release --nologo --framework $framework /p:SentryCLI=$cliStub @properties | ForEach-Object { Write-Host " $_"; $_ } + $output = dotnet build release-app -c Release --nologo --framework $framework @properties | ForEach-Object { Write-Host " $_"; $_ } $LASTEXITCODE | Should -Be 0 } finally { + Remove-Item env:SentryCLI Remove-Item $extraSourcePath -ErrorAction SilentlyContinue } [pscustomobject]@{ @@ -145,6 +164,16 @@ Describe 'Console apps () - release creation' -ForEach @( $calls | Should -AnyElementMatch '^releases new release-app@1\.2\.3\+abcdef\s*$' $calls | Should -AnyElementMatch '^releases set-commits --auto release-app@1\.2\.3\+abcdef\s*$' } + + It "skips uploads and release creation without failing the build when " -ForEach @( + @{ reason = 'there is no auth token'; cliError = 'error: Auth token is required for this request.'; expected = 'The Sentry CLI is not fully configured' } + @{ reason = 'the Sentry API request fails'; cliError = 'error: API request failed'; expected = 'warning : Sentry API request failed' } + ) { + $result = BuildWithSentryCLIStub '/p:SentryCreateRelease=true', '/p:SentryUploadSymbols=true' -stub (NewSentryCLIStubFailingInfo $cliError) + $result.Output | Should -AnyElementMatch $expected + $result.CliCalls | Should -HaveCount 1 + $result.CliCalls | Should -AnyElementMatch '^info\b' + } } Describe 'Console apps () - native AOT publish' -ForEach @( diff --git a/src/Sentry/buildTransitive/Sentry.targets b/src/Sentry/buildTransitive/Sentry.targets index 98c56a941f..731598b5e8 100644 --- a/src/Sentry/buildTransitive/Sentry.targets +++ b/src/Sentry/buildTransitive/Sentry.targets @@ -137,7 +137,8 @@ <_SentryCLICommand>$(SentryCLIBaseCommand) info <_SentryCLICommand Condition="'$(SentryOrg)' != '' And '$(SentryProject)' != ''">$(_SentryCLICommand) --no-defaults - + @@ -146,10 +147,10 @@ <_SentryCLIRequestFailed Condition="$(_SentryCLIOutput.Contains('API request failed'))">true + Text="Sentry API request failed. Either the authentication info is invalid, or the Sentry server could not be reached. Skipping Sentry uploads and release creation." /> + Text="The Sentry CLI is not fully configured with authentication, organization, and project. Skipping Sentry uploads and release creation." />