Skip to content

Commit

Permalink
Merge pull request #2111 from BlythMeister/TeamCityLogging
Browse files Browse the repository at this point in the history
Enhanced TeamCity Logging
  • Loading branch information
matthid committed Sep 27, 2018
2 parents 2c2a0f4 + 1f88af9 commit e4da873
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
30 changes: 23 additions & 7 deletions src/app/Fake.BuildServer.TeamCity/TeamCity.fs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ module TeamCityImportExtensions =
/// The general documentation on how to use CI server integration can be found [here](/buildserver.html).
/// This module does not provide any special APIs please use FAKE APIs and they should integrate into this CI server.
/// If some integration is not working as expected or you have features you would like to use directly please open an issue.
///
/// For more information on TeamCity interaction from builc scripts [see here](https://confluence.jetbrains.com/display/TCD18/Build+Script+Interaction+with+TeamCity)
[<RequireQualifiedAccess>]
module TeamCity =
open Fake.IO

// See https://confluence.jetbrains.com/display/TCD18/Build+Script+Interaction+with+TeamCity


/// Open Named Block that will be closed when the block is disposed
/// Usage: `use __ = TeamCity.block "My Block"`
Expand Down Expand Up @@ -222,6 +224,14 @@ module TeamCity =
(TeamCityWriter.encapsulateSpecialChars name) (TeamCityWriter.encapsulateSpecialChars message) (TeamCityWriter.encapsulateSpecialChars details)
(TeamCityWriter.encapsulateSpecialChars expected) (TeamCityWriter.encapsulateSpecialChars actual) |> TeamCityWriter.sendStrToTeamCity

/// Sends a warning message.
let internal warning message =
TeamCityWriter.sendToTeamCity "##teamcity[message text='%s' status='WARNING']" message

/// Sends an error message.
let internal error message =
TeamCityWriter.sendToTeamCity "##teamcity[message text='%s' status='ERROR']" message

/// TeamCity build parameters
///
/// See [Predefined Build Parameters documentation](https://confluence.jetbrains.com/display/TCD18/Predefined+Build+Parameters) for more information
Expand Down Expand Up @@ -365,9 +375,8 @@ module TeamCity =
with get() = RecentlyFailedTests.cache.Value

/// Implements a TraceListener for TeamCity build servers.
/// ## Parameters
/// - `importantMessagesToStdErr` - Defines whether to trace important messages to StdErr.
/// - `colorMap` - A function which maps TracePriorities to ConsoleColors.
///
/// See [the documentation](https://confluence.jetbrains.com/display/TCD18/Build+Script+Interaction+with+TeamCity) for more information
type internal TeamCityTraceListener() =

interface ITraceListener with
Expand All @@ -386,8 +395,10 @@ module TeamCity =
testFailed testName message detail
| TraceData.TestStatus (testName,TestStatus.Failed(message, detail, Some (expected, actual))) ->
comparisonFailure testName message detail expected actual
| TraceData.BuildState TagStatus.Success ->
reportBuildStatus "SUCCESS" "{build.status.text}"
| TraceData.BuildState state ->
ConsoleWriter.write false color true (sprintf "Changing BuildState to: %A" state)
reportBuildStatus "FAILURE" (sprintf "%s - {build.status.text}" (state.ToString()))
| TraceData.CloseTag (KnownTags.Test name, time, _) ->
finishTestCase name time
| TraceData.OpenTag (KnownTags.TestSuite name, _) ->
Expand All @@ -398,10 +409,15 @@ module TeamCity =
match description with
| Some d -> TeamCityWriter.sendOpenBlock tag.Name (sprintf "%s: %s" tag.Type d)
| _ -> TeamCityWriter.sendOpenBlock tag.Name tag.Type
| TraceData.CloseTag (tag, _, TagStatus.Failed) ->
TeamCityWriter.sendCloseBlock tag.Name
reportBuildStatus "FAILURE" (sprintf "Failure in %s" tag.Name)
| TraceData.CloseTag (tag, _, _) ->
TeamCityWriter.sendCloseBlock tag.Name
| TraceData.ImportantMessage text | TraceData.ErrorMessage text ->
ConsoleWriter.write false color true text
| TraceData.ImportantMessage text ->
warning text
| TraceData.ErrorMessage text ->
error text
| TraceData.LogMessage(text, newLine) | TraceData.TraceMessage(text, newLine) ->
ConsoleWriter.write false color newLine text
| TraceData.ImportData (ImportData.BuildArtifactWithName _, path)
Expand Down
6 changes: 5 additions & 1 deletion src/app/Fake.Core.Target/Target.fs
Original file line number Diff line number Diff line change
Expand Up @@ -444,11 +444,15 @@ module Target =
| Some e -> alignedError name time e.Message)

aligned "Total:" total null
if not context.HasError then aligned "Status:" "Ok" null
if not context.HasError then
aligned "Status:" "Ok" null
Trace.setBuildState TagStatus.Success
else
alignedError "Status:" "Failure" null
Trace.setBuildState TagStatus.Failed
else
Trace.traceError "No target was successfully completed"
Trace.setBuildState TagStatus.Warning

Trace.traceLine()

Expand Down

0 comments on commit e4da873

Please sign in to comment.