Custom Workflow Activity - Get Warnings from Build Details

368 views Asked by At

Ok, here's the thing:

I'm driving myself nuts trying to get the WARNINGS from a IBuildDetail object when invoking a CustomActivity.

This is what I've tried:

private static List<IBuildInformationNode> GetBuildWarnings(IBuildDetail buildInformation)
{
    var warnings = buildInformation.Information.GetNodesByType(InformationTypes.BuildWarning);

    if (warnings.Count == 0 && buildInformation.CompilationStatus == BuildPhaseStatus.Succeeded)
    {
        buildInformation.RefreshAllDetails();
        warnings = buildInformation.Information.GetNodesByType(InformationTypes.BuildWarning);
    }
    return warnings;
}

That gives me 0 WARNINGS.

I've also tried the same code using :

var warnings = InformationNodeConverters.GetBuildWarnings(buildInformation);

which still brings no warnings.

This CustomActivity is invoked at the end of the Workflow: I actually don't have any issues retrieving the rest of the details like build status, build errors, test information, etc.

The issue is only with the Warnings.

Funny thing is that, at the end of the build, when I check the build results, there ARE warnings.

Any ideas?

Thanks in advance!

2

There are 2 answers

1
Dylan Smith On

Is it possible that the warnings are happening after your custom activity is run. Can you examine the build log and see exactly where the warnings occur?

0
Delcho Milchev On

buildDetail.Information.GetNodesByType(InformationTypes.BuildWarning) does not return what you're looking for because messages from tracking participant are not flushed immediately.

InformationNodeConverters.GetBuildWarnings internally calls GetNodesByType(), thus it won't work for same reason.

Original information is kept in internal field of TrackingParticipant, thus it is inaccessible. Anyway, if you wait >15seconds, information from this internal field is flushed to accessible field.

Thus the ugly hack that does the job seems to be:

System.Threading.Thread.Sleep(16000);
var trackingParticipant = context.GetExtension<Microsoft.TeamFoundation.Build.Workflow.Tracking.BuildTrackingParticipant>();
var warnings = GetWarnings(trackingParticipant.GetActivityTracking(context));


    private List<IBuildInformationNode> GetWarnings(IActivityTracking activityTracking ){
        IBuildInformationNode rootNode = getRootNode( activityTracking.Node );
        return rootNode.Children.GetNodesByType(InformationTypes.BuildWarning, true);
    }

    private IBuildInformationNode getRootNode( IBuildInformationNode  node)
    {
        while( node.Parent != null ) node = node.Parent;
        return node;
    }