diff --git a/src/Sdk/AzurePipelines/AzureDevops.cs b/src/Sdk/AzurePipelines/AzureDevops.cs index 468743c3c5d..de83864f974 100644 --- a/src/Sdk/AzurePipelines/AzureDevops.cs +++ b/src/Sdk/AzurePipelines/AzureDevops.cs @@ -461,16 +461,15 @@ 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 = RelativeTo(context.RepositoryAndRef == finalRepository ? context.CWD ?? "." : "/", filename); if(finalFileName == null) { throw new Exception($"Couldn't find template location {filenameAndRef}"); } + var fileContent = await context.FileProvider.ReadFile(finalRepository, finalFileName); if(fileContent == null) { throw new Exception($"Couldn't read template {filenameAndRef} resolved to {finalFileName} ({finalRepository ?? "self"})"); @@ -478,6 +477,12 @@ public static async Task ReadTemplate(Runner.Server.Azure.Devops.C context.TraceWriter?.Info("{0}", $"Parsing template {filenameAndRef} resolved to {finalFileName} ({finalRepository ?? "self"}) using Schema {schemaName ?? "pipeline-root"}"); context.TraceWriter?.Verbose("{0}", fileContent); + var errorTemplateFileName = $"({finalRepository ?? "self"})/{finalFileName}"; + context.FileTable ??= new List(); + context.FileTable.Add(errorTemplateFileName); + var templateContext = AzureDevops.CreateTemplateContext(context.TraceWriter ?? new EmptyTraceWriter(), context.FileTable, context.Flags); + var fileId = templateContext.GetFileId(errorTemplateFileName); + TemplateToken token; using (var stringReader = new StringReader(fileContent)) { 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;