Skip to content

Commit f25bf83

Browse files
committed
Allow to overwrite ACTIONS_CACHE_URL environment variable
The runner script sets the `ACTIONS_CACHE_URL` using the value from the system connection. Currently, there's no way to override it. Some community users use custom cache solutions with self-hosted runners. They need to maintain a fork of `actions/runner` or `actions/toolkit`, and `actions/cache` to override the value in their solution. However it leads to significant maintenance work. If the runner script allows the `ACTIONS_CACHE_URL` value to be overridden by the `CUSTOM_ACTIONS_CACHE_URL` environment variable, it makes life a lot easier for the community, includes myself. An alternative solution could involve allowing the base URL value in `actions/toolkit` to be overridden. Several individuals have submitted similar PRs to this one actions/toolkit#1695, but they have not received adequate attention from the maintainers.
1 parent 078eb3b commit f25bf83

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/Runner.Worker/Handlers/ContainerActionHandler.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,13 @@ public async Task RunAsync(ActionRunStage stage)
219219
var systemConnection = ExecutionContext.Global.Endpoints.Single(x => string.Equals(x.Name, WellKnownServiceEndpointNames.SystemVssConnection, StringComparison.OrdinalIgnoreCase));
220220
Environment["ACTIONS_RUNTIME_URL"] = systemConnection.Url.AbsoluteUri;
221221
Environment["ACTIONS_RUNTIME_TOKEN"] = systemConnection.Authorization.Parameters[EndpointAuthorizationParameters.AccessToken];
222-
if (systemConnection.Data.TryGetValue("CacheServerUrl", out var cacheUrl) && !string.IsNullOrEmpty(cacheUrl))
222+
223+
string customCacheUrl = System.Environment.GetEnvironmentVariable("CUSTOM_ACTIONS_CACHE_URL");
224+
if (!string.IsNullOrEmpty(customCacheUrl))
225+
{
226+
Environment["ACTIONS_CACHE_URL"] = customCacheUrl;
227+
}
228+
else if (systemConnection.Data.TryGetValue("CacheServerUrl", out var cacheUrl) && !string.IsNullOrEmpty(cacheUrl))
223229
{
224230
Environment["ACTIONS_CACHE_URL"] = cacheUrl;
225231
}

src/Runner.Worker/Handlers/NodeScriptActionHandler.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,13 @@ public async Task RunAsync(ActionRunStage stage)
5454
var systemConnection = ExecutionContext.Global.Endpoints.Single(x => string.Equals(x.Name, WellKnownServiceEndpointNames.SystemVssConnection, StringComparison.OrdinalIgnoreCase));
5555
Environment["ACTIONS_RUNTIME_URL"] = systemConnection.Url.AbsoluteUri;
5656
Environment["ACTIONS_RUNTIME_TOKEN"] = systemConnection.Authorization.Parameters[EndpointAuthorizationParameters.AccessToken];
57-
if (systemConnection.Data.TryGetValue("CacheServerUrl", out var cacheUrl) && !string.IsNullOrEmpty(cacheUrl))
57+
58+
string customCacheUrl = System.Environment.GetEnvironmentVariable("CUSTOM_ACTIONS_CACHE_URL");
59+
if (!string.IsNullOrEmpty(customCacheUrl))
60+
{
61+
Environment["ACTIONS_CACHE_URL"] = customCacheUrl;
62+
}
63+
else if (systemConnection.Data.TryGetValue("CacheServerUrl", out var cacheUrl) && !string.IsNullOrEmpty(cacheUrl))
5864
{
5965
Environment["ACTIONS_CACHE_URL"] = cacheUrl;
6066
}

0 commit comments

Comments
 (0)