4

I am trying to get on an AzureDevOps project the number of Warning for a build task. But I still only get the first 10 warnings. How do you do it all? I especially need the number of warning, not necessarily the detail of the warning

var credential = new VssBasicCredential(string.Empty, myPat);
var connection = new VssConnection(new Uri(myCollection), credential);
var buildClient = connection.GetClient<BuildHttpClient>();
var timeline = buildClient.GetBuildTimelineAsync(myProject, myBuildId).Result;
var vsTask= timeline.Records.FirstOrDefault(p => p?.Task?.Name == "VSBuild");
// always 10 utmost  : warning and issues !!
var warning = vsTask.WarningCount;
var issues =  vsTask.Issues;
Krzysztof Madej
  • 32,704
  • 10
  • 78
  • 107
Philippe Auriou
  • 567
  • 4
  • 17

1 Answers1

3

This is really strange, but it looks that you cannot go above what is shown here

enter image description here

There is workaround (but it is a bit ugly). You can load log page and count warnings parsing the page.

static void Main(string[] args)
{
    var credential = new VssBasicCredential(string.Empty, "PAT");
    var connection = new VssConnection(new Uri("https://dev.azure.com/your-organization/"), credential);
    var buildClient = connection.GetClient<BuildHttpClient>();
    var timeline = buildClient.GetBuildTimelineAsync("yoyr project", 377).Result;

    var vsTask = timeline.Records.FirstOrDefault(p => p?.Task?.Name == "VSBuild");
    // always 10 utmost  : warning and issues !!
    var warning = vsTask.WarningCount;
    var issues = vsTask.Issues;
    Console.WriteLine(warning);


    HttpClient client = new HttpClient();
    var response =  client.GetAsync(vsTask.Log.Url);
    var pageContents = response.Result.Content.ReadAsStringAsync().Result;
    var realNumberOfWarnings = AllIndexesOf(pageContents, "##[warning]");
    Console.WriteLine(realNumberOfWarnings.Count);
    Console.ReadLine();
}

public static List<int> AllIndexesOf(string str, string value)
{
    if (String.IsNullOrEmpty(value))
        throw new ArgumentException("the string to find may not be empty", "value");
    List<int> indexes = new List<int>();
    for (int index = 0; ; index += value.Length)
    {
        index = str.IndexOf(value, index);
        if (index == -1)
            return indexes;
        indexes.Add(index);
    }
}

I hope it will help.

Please check what Tingluo Huang [MSFT] wrote here:

We should only count and store 10 errors/warning (i guess we having some counting bug, so we count to 11), those issues get stored in our backend DB for driving the build summary page render. We don't want to store too many errors/warning since most of the time the first few errors/warnings are key to the problem, and the rest are just noise.

Krzysztof Madej
  • 32,704
  • 10
  • 78
  • 107
  • 1
    thank you very much, yes it seems to be a limitation. it's a shame. To stay in an authenticated context var logs = buildClient.GetBuildLogLinesAsync(myProject, myBuildId, vsTask.Log.Id).Result; var warningCount = logs.Count(p => p.Contains("##[warning]")); – Philippe Auriou Apr 14 '20 at 07:28
  • 1
    Yes of course. I have public pipelines and thus I could do it as I did. – Krzysztof Madej Apr 14 '20 at 07:36