diff --git a/src/Microsoft.DotNet.ImageBuilder/src/ViewModel/TagInfo.cs b/src/Microsoft.DotNet.ImageBuilder/src/ViewModel/TagInfo.cs index 30442d71c..851d281d5 100644 --- a/src/Microsoft.DotNet.ImageBuilder/src/ViewModel/TagInfo.cs +++ b/src/Microsoft.DotNet.ImageBuilder/src/ViewModel/TagInfo.cs @@ -33,7 +33,7 @@ public static TagInfo Create( Model = model, BuildContextPath = buildContextPath }; - tagInfo.Name = variableHelper.SubstituteValues(name); + tagInfo.Name = variableHelper.SubstituteValues(name, tagInfo.GetVariableValue); tagInfo.FullyQualifiedName = GetFullyQualifiedName(repoName, tagInfo.Name); if (model.Syndication != null) @@ -55,5 +55,19 @@ public static string GetFullyQualifiedName(string repoName, string tagName) { return $"{repoName}:{tagName}"; } + + private string GetVariableValue(string variableType, string variableName) + { + string variableValue = null; + + if (string.Equals(variableType, VariableHelper.SystemVariableTypeId, StringComparison.Ordinal) + && string.Equals(variableName, VariableHelper.DockerfileGitCommitShaVariableName, StringComparison.Ordinal) + && BuildContextPath != null) + { + variableValue = GitHelper.GetCommitSha(BuildContextPath); + } + + return variableValue; + } } } diff --git a/src/Microsoft.DotNet.ImageBuilder/src/ViewModel/VariableHelper.cs b/src/Microsoft.DotNet.ImageBuilder/src/ViewModel/VariableHelper.cs index de58a8178..f9f68655f 100644 --- a/src/Microsoft.DotNet.ImageBuilder/src/ViewModel/VariableHelper.cs +++ b/src/Microsoft.DotNet.ImageBuilder/src/ViewModel/VariableHelper.cs @@ -13,9 +13,11 @@ namespace Microsoft.DotNet.ImageBuilder.ViewModel public class VariableHelper { private const char BuiltInDelimiter = ':'; + public const string DockerfileGitCommitShaVariableName = "DockerfileGitCommitSha"; public const string McrTagsYmlRepoTypeId = "McrTagsYmlRepo"; public const string McrTagsYmlTagGroupTypeId = "McrTagsYmlTagGroup"; public const string RepoVariableTypeId = "Repo"; + public const string SystemVariableTypeId = "System"; private const string VariableGroupName = "variable"; private static readonly string s_tagVariablePattern = $"\\$\\((?<{VariableGroupName}>[\\w:\\-.| ]+)\\)"; @@ -105,7 +107,14 @@ public VariableHelper(Manifest manifest, IManifestOptionsInfo options, Func