Skip to content

Commit

Permalink
Set runner environment in context and env (actions#2518)
Browse files Browse the repository at this point in the history
* Set runner environment in runner context and env

Extract runner_environment from the global context and expose in the
`github.runner` context and env as `RUNNER_ENVIRONMENT`.

Signed-off-by: Philip Harrison <philip@mailharrison.com>

* encoding.

---------

Signed-off-by: Philip Harrison <philip@mailharrison.com>
Co-authored-by: Tingluo Huang <tingluohuang@github.com>
  • Loading branch information
feelepxyz and TingluoHuang authored May 26, 2023
1 parent 8db8bbe commit 21b49c5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/Runner.Worker/JobRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ public async Task<TaskResult> RunAsync(AgentJobRequestMessage message, Cancellat
_runnerSettings = HostContext.GetService<IConfigurationStore>().GetSettings();
jobContext.SetRunnerContext("name", _runnerSettings.AgentName);

if (jobContext.Global.Variables.TryGetValue(WellKnownDistributedTaskVariables.RunnerEnvironment, out var runnerEnvironment))
{
jobContext.SetRunnerContext("environment", runnerEnvironment);
}

string toolsDirectory = HostContext.GetDirectory(WellKnownDirectory.Tools);
Directory.CreateDirectory(toolsDirectory);
jobContext.SetRunnerContext("tool_cache", toolsDirectory);
Expand Down
3 changes: 2 additions & 1 deletion src/Sdk/DTWebApi/WebApi/WellKnownDistributedTaskVariables.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using System;
using System;

namespace GitHub.DistributedTask.WebApi
{
public static class WellKnownDistributedTaskVariables
{
public static readonly String JobId = "system.jobId";
public static readonly String RunnerLowDiskspaceThreshold = "system.runner.lowdiskspacethreshold";
public static readonly String RunnerEnvironment = "system.runnerEnvironment";
}
}

0 comments on commit 21b49c5

Please sign in to comment.