diff --git a/src/Sdk/AzurePipelines/AzureDevops.cs b/src/Sdk/AzurePipelines/AzureDevops.cs index 17085033c0e..3c67c60cf1d 100644 --- a/src/Sdk/AzurePipelines/AzureDevops.cs +++ b/src/Sdk/AzurePipelines/AzureDevops.cs @@ -461,16 +461,20 @@ public static string RelativeTo(string cwd, string filename) { public static async Task ReadTemplate(Runner.Server.Azure.Devops.Context context, string filenameAndRef, Dictionary cparameters = null, string schemaName = null) { var variables = context.VariablesProvider?.GetVariablesForEnvironment(""); - var templateContext = AzureDevops.CreateTemplateContext(context.TraceWriter ?? new EmptyTraceWriter(), new List(), context.Flags); var afilenameAndRef = filenameAndRef.Split("@", 2); var filename = afilenameAndRef[0]; - var fileId = templateContext.GetFileId(filename); // Read the file var finalRepository = afilenameAndRef.Length == 1 ? context.RepositoryAndRef : string.Equals(afilenameAndRef[1], "self", StringComparison.OrdinalIgnoreCase) ? null : (context.Repositories?.TryGetValue(afilenameAndRef[1], out var ralias) ?? false) ? ralias : throw new Exception($"Couldn't find repository with alias {afilenameAndRef[1]} in repository resources"); var finalFileName = context.RepositoryAndRef == finalRepository ? RelativeTo(context.CWD ?? ".", filename) : filename; if(finalFileName == null) { throw new Exception($"Couldn't find template location {filenameAndRef}"); } + + context.FileTable ??= new List(); + context.FileTable.Add(finalFileName); + var templateContext = AzureDevops.CreateTemplateContext(context.TraceWriter ?? new EmptyTraceWriter(), context.FileTable, context.Flags); + var fileId = templateContext.GetFileId(finalFileName); + var fileContent = await context.FileProvider.ReadFile(finalRepository, finalFileName); if(fileContent == null) { throw new Exception($"Couldn't read template {filenameAndRef} resolved to {finalFileName} ({finalRepository ?? "self"})"); diff --git a/src/Sdk/AzurePipelines/Context.cs b/src/Sdk/AzurePipelines/Context.cs index 07bf2a36d95..16e39882b64 100644 --- a/src/Sdk/AzurePipelines/Context.cs +++ b/src/Sdk/AzurePipelines/Context.cs @@ -16,6 +16,7 @@ public class Context { public ITaskByNameAndVersionProvider TaskByNameAndVersion { get; set; } public IRequiredParametersProvider RequiredParametersProvider { get; set; } + public List FileTable { get; set; } = new List(); public Context Clone() { return MemberwiseClone() as Context;