Skip to content

Commit 8c649d8

Browse files
brettfobaronfel
authored andcommitted
improve build telemetry (#8239)
* add windows build telemetry * fix linux build telemetry
1 parent 13efffc commit 8c649d8

File tree

2 files changed

+35
-21
lines changed

2 files changed

+35
-21
lines changed

eng/Build.ps1

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ param (
6161

6262
Set-StrictMode -version 2.0
6363
$ErrorActionPreference = "Stop"
64+
$BuildCategory = ""
65+
$BuildMessage = ""
6466

6567
function Print-Usage() {
6668
Write-Host "Common settings:"
@@ -303,6 +305,9 @@ function EnablePreviewSdks() {
303305
}
304306

305307
try {
308+
$script:BuildCategory = "Build"
309+
$script:BuildMessage = "Failure preparing build"
310+
306311
Process-Arguments
307312

308313
. (Join-Path $PSScriptRoot "build-utils.ps1")
@@ -317,9 +322,11 @@ try {
317322
}
318323

319324
if ($bootstrap) {
325+
$script:BuildMessage = "Failure building bootstrap compiler"
320326
$bootstrapDir = Make-BootstrapBuild
321327
}
322328

329+
$script:BuildMessage = "Failure building product"
323330
if ($restore -or $build -or $rebuild -or $pack -or $sign -or $publish) {
324331
if ($noVisualStudio) {
325332
BuildCompiler
@@ -332,6 +339,8 @@ try {
332339
VerifyAssemblyVersionsAndSymbols
333340
}
334341

342+
$script:BuildCategory = "Test"
343+
$script:BuildMessage = "Failure running tests"
335344
$desktopTargetFramework = "net472"
336345
$coreclrTargetFramework = "netcoreapp3.0"
337346

@@ -421,6 +430,7 @@ catch {
421430
Write-Host $_
422431
Write-Host $_.Exception
423432
Write-Host $_.ScriptStackTrace
433+
Write-PipelineTelemetryError -Category $script:BuildCategory -Message $script:BuildMessage
424434
ExitWithExitCode 1
425435
}
426436
finally {

eng/build.sh

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ properties=""
6666
docker=false
6767
args=""
6868

69+
BuildCategory=""
70+
BuildMessage=""
71+
6972
if [[ $# = 0 ]]
7073
then
7174
usage
@@ -150,6 +153,8 @@ done
150153
. "$scriptroot/common/tools.sh"
151154

152155
function TestUsingNUnit() {
156+
BuildCategory="Test"
157+
BuildMessage="Error running tests"
153158
testproject=""
154159
targetframework=""
155160
while [[ $# > 0 ]]; do
@@ -180,14 +185,12 @@ function TestUsingNUnit() {
180185
projectname="${projectname%.*}"
181186
testlogpath="$artifacts_dir/TestResults/$configuration/${projectname}_$targetframework.xml"
182187
args="test \"$testproject\" --no-restore --no-build -c $configuration -f $targetframework --test-adapter-path . --logger \"nunit;LogFilePath=$testlogpath\""
183-
"$DOTNET_INSTALL_DIR/dotnet" $args || {
184-
local exit_code=$?
185-
Write-PipelineTelemetryError -category 'Test' "dotnet test failed for $testproject:$targetframework (exit code $exit_code)."
186-
ExitWithExitCode $exit_code
187-
}
188+
"$DOTNET_INSTALL_DIR/dotnet" $args || exit $?
188189
}
189190

190191
function BuildSolution {
192+
BuildCategory="Build"
193+
BuildMessage="Error preparing build"
191194
local solution="FSharp.sln"
192195
echo "$solution:"
193196

@@ -229,33 +232,28 @@ function BuildSolution {
229232
rm -fr $bootstrap_dir
230233
fi
231234
if [ ! -f "$bootstrap_dir/fslex.dll" ]; then
235+
BuildMessage="Error building tools"
232236
MSBuild "$repo_root/src/buildtools/buildtools.proj" \
233237
/restore \
234238
/p:Configuration=$bootstrap_config \
235-
/t:Publish || {
236-
local exit_code=$?
237-
Write-PipelineTelemetryError -category 'Build' "Error building buildtools (exit code '$exit_code')."
238-
ExitWithExitCode $exit_code
239-
}
239+
/t:Publish
240240

241241
mkdir -p "$bootstrap_dir"
242242
cp -pr $artifacts_dir/bin/fslex/$bootstrap_config/netcoreapp3.0/publish $bootstrap_dir/fslex
243243
cp -pr $artifacts_dir/bin/fsyacc/$bootstrap_config/netcoreapp3.0/publish $bootstrap_dir/fsyacc
244244
fi
245245
if [ ! -f "$bootstrap_dir/fsc.exe" ]; then
246+
BuildMessage="Error building bootstrap"
246247
MSBuild "$repo_root/proto.proj" \
247248
/restore \
248249
/p:Configuration=$bootstrap_config \
249-
/t:Publish || {
250-
local exit_code=$?
251-
Write-PipelineTelemetryError -category 'Build' "Error building bootstrap compiler (exit code '$exit_code')."
252-
ExitWithExitCode $exit_code
253-
}
250+
/t:Publish
254251

255252
cp -pr $artifacts_dir/bin/fsc/$bootstrap_config/netcoreapp3.0/publish $bootstrap_dir/fsc
256253
fi
257254

258255
# do real build
256+
BuildMessage="Error building solution"
259257
MSBuild $toolset_build_proj \
260258
$bl \
261259
/v:$verbosity \
@@ -271,13 +269,20 @@ function BuildSolution {
271269
/p:ContinuousIntegrationBuild=$ci \
272270
/p:QuietRestore=$quiet_restore \
273271
/p:QuietRestoreBinaryLog="$binary_log" \
274-
$properties || {
275-
local exit_code=$?
276-
Write-PipelineTelemetryError -category 'Build' "Error building solution (exit code '$exit_code')."
277-
ExitWithExitCode $exit_code
278-
}
272+
$properties
273+
}
274+
275+
function TrapAndReportError {
276+
local exit_code=$?
277+
if [[ ! $exit_code == 0 ]]; then
278+
Write-PipelineTelemetryError -category $BuildCategory "$BuildMessage (exit code '$exit_code')."
279+
ExitWithExitCode $exit_code
280+
fi
279281
}
280282

283+
# allow early termination to report the appropriate build failure reason
284+
trap TrapAndReportError EXIT
285+
281286
InitializeDotNetCli $restore
282287

283288
BuildSolution
@@ -293,4 +298,3 @@ if [[ "$test_core_clr" == true ]]; then
293298
fi
294299

295300
ExitWithExitCode 0
296-

0 commit comments

Comments
 (0)