Search code examples
c#azureazure-batch

How to list all tasks in an Azure Batch account using the .NET API?


In my Azure Batch account, I run many jobs simultaneously. How can I get all tasks across all jobs?


Solution

  • Use BatchClient.JobOperations's ListJobs() and ListTasks():

    using Microsoft.Azure.Batch;
    using Microsoft.Azure.Batch.Auth;
    /*...*/
    
    var BatchClient = BatchClient.Open(new BatchSharedKeyCredentials(
      "<your-batch-endpoint>", 
      "<your-batch-account-name>", 
      "<your-shared-key>"));
    var jobs = BatchClient.JobOperations.ListJobs();
    var tasks = jobs.SelectMany(job => BatchClient.JobOperations.ListTasks(job.Id));