Skip to content

Commit

Permalink
Adding a new vars context for non-secret variables (#2096)
Browse files Browse the repository at this point in the history
* Adding a new vars context for non-secret variables

* Fix test case

* Trigger checks

* Remove variables from env context and environment varibale

* remove extra references

* Add prefix handling to configuration variables

* Fix test cases

* Consume variables using vars in context data

* removed action_yaml changes
  • Loading branch information
tauhid621 committed Sep 30, 2022
1 parent 01ff38f commit dca4f67
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public sealed class PipelineTemplateConstants
public const String TimeoutMinutes = "timeout-minutes";
public const String Username = "username";
public const String Uses = "uses";
public const String Vars = "vars";
public const String VmImage = "vmImage";
public const String Volumes = "volumes";
public const String With = "with";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,7 @@ internal static ContainerRegistryCredentials ConvertToContainerCredentials(Templ
{
new NamedValueInfo<NoOperationNamedValue>(PipelineTemplateConstants.GitHub),
new NamedValueInfo<NoOperationNamedValue>(PipelineTemplateConstants.Needs),
new NamedValueInfo<NoOperationNamedValue>(PipelineTemplateConstants.Vars),
};
private static readonly INamedValueInfo[] s_stepNamedValues = new INamedValueInfo[]
{
Expand All @@ -643,6 +644,7 @@ internal static ContainerRegistryCredentials ConvertToContainerCredentials(Templ
new NamedValueInfo<NoOperationNamedValue>(PipelineTemplateConstants.Runner),
new NamedValueInfo<NoOperationNamedValue>(PipelineTemplateConstants.Env),
new NamedValueInfo<NoOperationNamedValue>(PipelineTemplateConstants.Needs),
new NamedValueInfo<NoOperationNamedValue>(PipelineTemplateConstants.Vars),
};
private static readonly IFunctionInfo[] s_stepConditionFunctions = new IFunctionInfo[]
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ public class PipelineTemplateEvaluator
PipelineTemplateConstants.Job,
PipelineTemplateConstants.Runner,
PipelineTemplateConstants.Env,
PipelineTemplateConstants.Vars,
};
private readonly String[] s_expressionFunctionNames = new[]
{
Expand Down
51 changes: 37 additions & 14 deletions src/Sdk/DTPipelines/workflow-v1.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"workflow-env": {
"context": [
"github",
"secrets"
"secrets",
"vars"
],
"mapping": {
"loose-key-type": "non-empty-string",
Expand Down Expand Up @@ -86,6 +87,7 @@
"context": [
"github",
"needs",
"vars",
"always(0,0)",
"failure(0,MAX)",
"cancelled(0,0)",
Expand All @@ -98,6 +100,7 @@
"context": [
"github",
"needs",
"vars",
"always(0,0)",
"failure(0,MAX)",
"cancelled(0,0)",
Expand All @@ -116,7 +119,8 @@
"strategy": {
"context": [
"github",
"needs"
"needs",
"vars"
],
"mapping": {
"properties": {
Expand Down Expand Up @@ -156,7 +160,8 @@
"github",
"needs",
"strategy",
"matrix"
"matrix",
"vars"
],
"one-of": [
"non-empty-string",
Expand All @@ -182,7 +187,8 @@
"needs",
"strategy",
"matrix",
"secrets"
"secrets",
"vars"
],
"mapping": {
"loose-key-type": "non-empty-string",
Expand All @@ -204,7 +210,8 @@
"strategy",
"matrix",
"needs",
"env"
"env",
"vars"
],
"mapping": {
"properties": {
Expand Down Expand Up @@ -281,6 +288,7 @@
"job",
"runner",
"env",
"vars",
"always(0,0)",
"failure(0,0)",
"cancelled(0,0)",
Expand All @@ -299,6 +307,7 @@
"job",
"runner",
"env",
"vars",
"always(0,0)",
"failure(0,0)",
"cancelled(0,0)",
Expand Down Expand Up @@ -326,6 +335,7 @@
"job",
"runner",
"env",
"vars",
"hashFiles(1,255)"
],
"mapping": {
Expand All @@ -345,6 +355,7 @@
"job",
"runner",
"env",
"vars",
"hashFiles(1,255)"
],
"mapping": {
Expand All @@ -358,7 +369,8 @@
"github",
"needs",
"strategy",
"matrix"
"matrix",
"vars"
],
"one-of": [
"string",
Expand All @@ -384,7 +396,8 @@
"github",
"needs",
"strategy",
"matrix"
"matrix",
"vars"
],
"mapping": {
"loose-key-type": "non-empty-string",
Expand All @@ -397,7 +410,8 @@
"github",
"needs",
"strategy",
"matrix"
"matrix",
"vars"
],
"one-of": [
"non-empty-string",
Expand All @@ -409,7 +423,8 @@
"context": [
"secrets",
"env",
"github"
"github",
"vars"
],
"mapping": {
"properties": {
Expand Down Expand Up @@ -443,7 +458,8 @@
"github",
"needs",
"strategy",
"matrix"
"matrix",
"vars"
],
"boolean": {}
},
Expand All @@ -453,7 +469,8 @@
"github",
"needs",
"strategy",
"matrix"
"matrix",
"vars"
],
"number": {}
},
Expand All @@ -463,7 +480,8 @@
"github",
"needs",
"strategy",
"matrix"
"matrix",
"vars"
],
"string": {}
},
Expand All @@ -479,6 +497,7 @@
"job",
"runner",
"env",
"vars",
"hashFiles(1,255)"
],
"boolean": {}
Expand All @@ -495,6 +514,7 @@
"job",
"runner",
"env",
"vars",
"hashFiles(1,255)"
],
"number": {}
Expand All @@ -510,7 +530,8 @@
"steps",
"job",
"runner",
"env"
"env",
"vars"
],
"string": {}
},
Expand All @@ -524,7 +545,8 @@
"steps",
"job",
"runner",
"env"
"env",
"vars"
],
"string": {}
},
Expand All @@ -540,6 +562,7 @@
"job",
"runner",
"env",
"vars",
"hashFiles(1,255)"
],
"string": {}
Expand Down
45 changes: 45 additions & 0 deletions src/Test/L0/Worker/ExecutionContextL0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,51 @@ public void GetExpressionValues_ContainerStepHost()
}
}

[Fact]
[Trait("Level", "L0")]
[Trait("Category", "Worker")]
public void ActionVariables_AddedToVarsContext()
{
using (TestHostContext hc = CreateTestContext())
{
TaskOrchestrationPlanReference plan = new TaskOrchestrationPlanReference();
TimelineReference timeline = new TimelineReference();
Guid jobId = Guid.NewGuid();
string jobName = "some job name";
var jobRequest = new Pipelines.AgentJobRequestMessage(plan, timeline, jobId, jobName, jobName, null, null, null, new Dictionary<string, VariableValue>(), new List<MaskHint>(), new Pipelines.JobResources(), new Pipelines.ContextData.DictionaryContextData(), new Pipelines.WorkspaceOptions(), new List<Pipelines.ActionStep>(), null, null, null, null);
jobRequest.Resources.Repositories.Add(new Pipelines.RepositoryResource()
{
Alias = Pipelines.PipelineConstants.SelfAlias,
Id = "github",
Version = "sha1"
});
jobRequest.ContextData["github"] = new Pipelines.ContextData.DictionaryContextData();

var inputVarsContext = new DictionaryContextData();

inputVarsContext["VARIABLE_1"] = new StringContextData("value1");
inputVarsContext["VARIABLE_2"] = new StringContextData("value2");
jobRequest.ContextData["vars"] = inputVarsContext;

// Arrange: Setup the paging logger.
var pagingLogger1 = new Mock<IPagingLogger>();
var jobServerQueue = new Mock<IJobServerQueue>();
hc.EnqueueInstance(pagingLogger1.Object);
hc.SetSingleton(jobServerQueue.Object);

var jobContext = new Runner.Worker.ExecutionContext();
jobContext.Initialize(hc);

jobContext.InitializeJob(jobRequest, CancellationToken.None);

var expected = new DictionaryContextData();
expected["VARIABLE_1"] = new StringContextData("value1");
expected["VARIABLE_2"] = new StringContextData("value1");

Assert.True(ExpressionValuesAssertEqual(expected, jobContext.ExpressionValues["vars"] as DictionaryContextData));
}
}

private bool ExpressionValuesAssertEqual(DictionaryContextData expect, DictionaryContextData actual)
{
foreach (var key in expect.Keys.ToList())
Expand Down

0 comments on commit dca4f67

Please sign in to comment.