Skip to content

Commit deada1c

Browse files
fix(msbuild): Don't fail the build when sentry-cli has no auth token (#5705)
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 <noreply@anthropic.com>
1 parent 7abb8dd commit deada1c

2 files changed

Lines changed: 35 additions & 5 deletions

File tree

‎integration-test/cli.Tests.ps1‎

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,21 +71,40 @@ Describe 'Console apps (<framework>) - release creation' -ForEach @(
7171
chmod +x $cliStub
7272
}
7373

74-
function BuildWithSentryCLIStub([string[]] $properties, [string] $extraSource)
74+
function NewSentryCLIStubFailingInfo([string] $cliError)
75+
{
76+
if ($IsWindows)
77+
{
78+
$stub = Join-Path $PSScriptRoot 'release-app' 'sentry-cli-failing.cmd'
79+
"@echo %* >> `"$cliLog`"`n@if `"%1`"==`"info`" (echo $cliError 1>&2 & exit 1)" | Set-Content $stub
80+
}
81+
else
82+
{
83+
$stub = Join-Path $PSScriptRoot 'release-app' 'sentry-cli-failing.sh'
84+
"#!/bin/sh`necho `"`$*`" >> `"$cliLog`"`nif [ `"`$1`" = info ]; then echo '$cliError' >&2; exit 1; fi" | Set-Content $stub
85+
chmod +x $stub
86+
}
87+
$stub
88+
}
89+
90+
function BuildWithSentryCLIStub([string[]] $properties, [string] $extraSource, [string] $stub = $cliStub)
7591
{
7692
Remove-Item $cliLog -ErrorAction SilentlyContinue
7793
$extraSourcePath = Join-Path $PSScriptRoot 'release-app' 'Extra.cs'
7894
if ($extraSource)
7995
{
8096
$extraSource | Set-Content $extraSourcePath
8197
}
98+
# Not /p:SentryCLI, because the targets can't clear a global property when the CLI isn't configured
99+
$env:SentryCLI = $stub
82100
try
83101
{
84-
$output = dotnet build release-app -c Release --nologo --framework $framework /p:SentryCLI=$cliStub @properties | ForEach-Object { Write-Host " $_"; $_ }
102+
$output = dotnet build release-app -c Release --nologo --framework $framework @properties | ForEach-Object { Write-Host " $_"; $_ }
85103
$LASTEXITCODE | Should -Be 0
86104
}
87105
finally
88106
{
107+
Remove-Item env:SentryCLI
89108
Remove-Item $extraSourcePath -ErrorAction SilentlyContinue
90109
}
91110
[pscustomobject]@{
@@ -145,6 +164,16 @@ Describe 'Console apps (<framework>) - release creation' -ForEach @(
145164
$calls | Should -AnyElementMatch '^releases new release-app@1\.2\.3\+abcdef\s*$'
146165
$calls | Should -AnyElementMatch '^releases set-commits --auto release-app@1\.2\.3\+abcdef\s*$'
147166
}
167+
168+
It "skips uploads and release creation without failing the build when <reason>" -ForEach @(
169+
@{ reason = 'there is no auth token'; cliError = 'error: Auth token is required for this request.'; expected = 'The Sentry CLI is not fully configured' }
170+
@{ reason = 'the Sentry API request fails'; cliError = 'error: API request failed'; expected = 'warning : Sentry API request failed' }
171+
) {
172+
$result = BuildWithSentryCLIStub '/p:SentryCreateRelease=true', '/p:SentryUploadSymbols=true' -stub (NewSentryCLIStubFailingInfo $cliError)
173+
$result.Output | Should -AnyElementMatch $expected
174+
$result.CliCalls | Should -HaveCount 1
175+
$result.CliCalls | Should -AnyElementMatch '^info\b'
176+
}
148177
}
149178

150179
Describe 'Console apps (<framework>) - native AOT publish' -ForEach @(

‎src/Sentry/buildTransitive/Sentry.targets‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@
137137
<_SentryCLICommand>$(SentryCLIBaseCommand) info</_SentryCLICommand>
138138
<_SentryCLICommand Condition="'$(SentryOrg)' != '' And '$(SentryProject)' != ''">$(_SentryCLICommand) --no-defaults</_SentryCLICommand>
139139
</PropertyGroup>
140-
<Exec Condition="'$(SentryCLI)' != ''" Command="$(_SentryCLICommand)" IgnoreExitCode="true" ConsoleToMsBuild="true" StandardOutputImportance="Low">
140+
<Exec Condition="'$(SentryCLI)' != ''" Command="$(_SentryCLICommand)" IgnoreExitCode="true" IgnoreStandardErrorWarningFormat="true"
141+
ConsoleToMsBuild="true" StandardOutputImportance="Low" StandardErrorImportance="Normal">
141142
<Output TaskParameter="ExitCode" PropertyName="_SentryCLIExitCode" />
142143
<Output TaskParameter="ConsoleOutput" PropertyName="_SentryCLIOutput" />
143144
</Exec>
@@ -146,10 +147,10 @@
146147
<_SentryCLIRequestFailed Condition="$(_SentryCLIOutput.Contains('API request failed'))">true</_SentryCLIRequestFailed>
147148
</PropertyGroup>
148149
<Warning Condition="'$(_SentryCLIRequestFailed)' != ''"
149-
Text="Sentry API request failed. Either the authentication info is invalid, or the Sentry server could not be reached." />
150+
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." />
150151

151152
<Message Importance="High" Condition="'$(_SentryCLIExitCode)' != '0' And '$(_SentryCLIRequestFailed)' == ''"
152-
Text="The Sentry CLI is not fully configured with authentication, organization, and project." />
153+
Text="The Sentry CLI is not fully configured with authentication, organization, and project. Skipping Sentry uploads and release creation." />
153154
<PropertyGroup Condition="'$(_SentryCLIExitCode)' != '0'">
154155
<SentryCLI />
155156
</PropertyGroup>

0 commit comments

Comments
 (0)