Skip to content

JetBrains/TeamCity.ServiceMessages

Repository files navigation

Service Messages .NET library for

NuGet TeamCity.Dotnet.Integration License

This library provides read/write access to TeamCity Service messages. Take a look at the description of service messages at this page.

Usage:

Most use cases are covered in tests.

To create service message, use:

JetBrains.TeamCity.ServiceMessages.Write.ServiceMessageFormatter.FormatMessage

To parse service messages, use:

JetBrains.TeamCity.ServiceMessages.Read.ServiceMessageParser.ParseServiceMessages

There is an API to generate TeamCity specific service messages, use:

JetBrains.TeamCity.ServiceMessages.Write.Special.ITeamCityWriter

to get the instance of the object create an instance of the factory and get it by:

new JetBrains.TeamCity.ServiceMessages.Write.Special.TeamCityServiceMessages().CreateWriter()

for example:

// Creating the root writer
using (var writer = new TeamCityServiceMessages().CreateWriter(Console.WriteLine))
// Creating the build log block "Tests"
using (var block = writer.OpenBlock("Tests"))
// Creating the test suite "Tests"
using (var testClass = block.OpenTestSuite("TestClass"))
{
    // Creating the successful test
    using (var test = testClass.OpenTest("Successful"))
    {
        test.WriteStdOutput("Some output");
        test.WriteDuration(TimeSpan.FromSeconds(1));
    }

    // Creating the ignored test
    using (var test = testClass.OpenTest("Ignored"))
    {
        test.WriteIgnored();
    }

    // Creating the failed test
    using (var test = testClass.OpenTest("Failed"))
    {
        test.WriteFailed("Some message", "Details");
    }

    // Attaching an image to test
    using (var test = testClass.OpenTest("Image"))
    {
        writer.PublishArtifact(Path.GetFullPath("TeamCity.png") + " => TestData");
        test.WriteImage("TestData/TeamCity.png", "Team City Logo");
    }

    // Attaching a value to test
    using (var test = testClass.OpenTest("Value"))
    {
        test.WriteValue(1234.56.ToString(CultureInfo.InvariantCulture), "Some Value");
    }

    // Attaching a file to test
    using (var test = testClass.OpenTest("File"))
    {
        writer.PublishArtifact(Path.GetFullPath("TeamCity.png") + " => TestData");
        test.WriteFile("TestData/TeamCity.png", "Team City Logo file");
    }

    // Attaching a link to test
    using (var test = testClass.OpenTest("Link"))
    {
        test.WriteLink("https://www.jetbrains.com/", "JetBrains");
    }
}