diff --git a/src/Runner.Worker/ExecutionContext.cs b/src/Runner.Worker/ExecutionContext.cs index b49fab72b..83e47c74c 100644 --- a/src/Runner.Worker/ExecutionContext.cs +++ b/src/Runner.Worker/ExecutionContext.cs @@ -105,7 +105,6 @@ namespace GitHub.Runner.Worker // others void ForceTaskComplete(); void RegisterPostJobStep(IStep step); - public void SetEnvironmentVariables(Dictionary dict); void RegisterNestedStep(IStep step, DictionaryContextData inputsData, int location, Dictionary envData); } @@ -281,13 +280,19 @@ namespace GitHub.Runner.Worker // Add the composite action environment variables to each step. // If the key already exists, we override it since the composite action env variables will have higher precedence // Note that for each composite action step, it's environment variables will be set in the StepRunner automatically - step.ExecutionContext.SetEnvironmentVariables(envData); - Root.JobSteps.Insert(location, step); - } + // step.ExecutionContext.SetEnvironmentVariables(envData); +#if OS_WINDOWS + var envContext = new DictionaryContextData(); +#else + var envContext = new CaseSensitiveDictionaryContextData(); +#endif + foreach (var pair in envData) + { + envContext[pair.Key] = new StringContextData(pair.Value ?? string.Empty); + } + step.ExecutionContext.ExpressionValues["env"] = envContext; - public void SetEnvironmentVariables(Dictionary dict) - { - this.EnvironmentVariables = dict; + Root.JobSteps.Insert(location, step); } public IExecutionContext CreateChild(Guid recordId, string displayName, string refName, string scopeName, string contextName, Dictionary intraActionState = null, int? recordOrder = null) diff --git a/src/Runner.Worker/StepsRunner.cs b/src/Runner.Worker/StepsRunner.cs index e75d2e106..966f73dc1 100644 --- a/src/Runner.Worker/StepsRunner.cs +++ b/src/Runner.Worker/StepsRunner.cs @@ -93,12 +93,28 @@ namespace GitHub.Runner.Worker #else var envContext = new CaseSensitiveDictionaryContextData(); #endif - step.ExecutionContext.ExpressionValues["env"] = envContext; + // Global env foreach (var pair in step.ExecutionContext.EnvironmentVariables) { envContext[pair.Key] = new StringContextData(pair.Value ?? string.Empty); } + // Stomps over with outside step env + if (step.ExecutionContext.ExpressionValues.TryGetValue("env", out var envContextData)) + { +#if OS_WINDOWS + var dict = envContextData as DictionaryContextData; +#else + var dict = envContextData as CaseSensitiveDictionaryContextData; +#endif + foreach (var pair in dict) + { + envContext[pair.Key] = pair.Value; + } + } + + step.ExecutionContext.ExpressionValues["env"] = envContext; + bool evaluateStepEnvFailed = false; if (step is IActionRunner actionStep) {