Search code examples
c#.netazureazure-batch

Azure Batch - ResourceFiles PreparationTask


I'm trying to use a PreparationTask to grab my ResourceFiles to be used as input data.

My prep task looks like this:

myJob.JobPreparationTask = new JobPreparationTask { CommandLine = jobPrepCmdLine };

How do I configure my job with a PreparationTask to download ResourceFiles from my AutoStorageContainer to pool VM's?

I tried:

var inputFiles = new List<ResourceFile> { };
var file = ResourceFile.FromAutoStorageContainer("fgrp-jill2");  
inputFiles.Add(file); 

myJob.JobPreparationTask.ResourceFiles = inputFiles;

But get a null object error, even when the inputFiles.Add is showing at least 1 file recognized.


Solution

  • You should use the Storage SDK in conjunction with Batch in this scenario. You can follow this as an example: https://learn.microsoft.com/en-us/azure/batch/quick-run-dotnet#preliminaries

    A Job preparation task functions very similar to a regular Start Task in that it runs before the tasks execution. In the example from the link, you'll see that we reference the Blob client, container name and file path. I'll paste the sample here:

    List<string> inputFilePaths = new List<string>
    {
        "taskdata0.txt",
        "taskdata1.txt",
        "taskdata2.txt"
    };
    
    List<ResourceFile> inputFiles = new List<ResourceFile>();
    
    foreach (string filePath in inputFilePaths)
    {
        inputFiles.Add(UploadFileToContainer(blobClient, inputContainerName, filePath));
    }