@@ -66,6 +66,9 @@ properties=""
6666docker=false
6767args=" "
6868
69+ BuildCategory=" "
70+ BuildMessage=" "
71+
6972if [[ $# = 0 ]]
7073then
7174 usage
150153. " $scriptroot /common/tools.sh"
151154
152155function 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
190191function 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+
281286InitializeDotNetCli $restore
282287
283288BuildSolution
@@ -293,4 +298,3 @@ if [[ "$test_core_clr" == true ]]; then
293298fi
294299
295300ExitWithExitCode 0
296-
0 commit comments