From 1096b975e42dc49ea79db1151bc8616de7091928 Mon Sep 17 00:00:00 2001 From: Dylan Geraci <67774922+heavymachinery@users.noreply.github.com> Date: Fri, 16 Jun 2023 00:13:08 -0400 Subject: [PATCH] Send environment url to Run Service (#2650) * add EnvironmentUrl to CompleteJobRequest * Send environment url to Run Service * Fix whitespace * Fix test * Fix more whitespace * Apply suggestions from code review Co-authored-by: Tingluo Huang * Apply suggestion from code review Co-authored-by: Tingluo Huang --------- Co-authored-by: Tingluo Huang --- src/Runner.Common/RunServer.cs | 4 +++- src/Runner.Listener/JobDispatcher.cs | 2 +- src/Runner.Worker/JobRunner.cs | 10 +++++++++- src/Sdk/RSWebApi/Contracts/CompleteJobRequest.cs | 3 +++ src/Sdk/RSWebApi/RunServiceHttpClient.cs | 4 +++- src/Test/L0/Worker/JobRunnerL0.cs | 3 ++- 6 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/Runner.Common/RunServer.cs b/src/Runner.Common/RunServer.cs index 3bd60ece0..fbd9ff96a 100644 --- a/src/Runner.Common/RunServer.cs +++ b/src/Runner.Common/RunServer.cs @@ -26,6 +26,7 @@ namespace GitHub.Runner.Common Dictionary outputs, IList stepResults, IList jobAnnotations, + string environmentUrl, CancellationToken token); Task RenewJobAsync(Guid planId, Guid jobId, CancellationToken token); @@ -70,11 +71,12 @@ namespace GitHub.Runner.Common Dictionary outputs, IList stepResults, IList jobAnnotations, + string environmentUrl, CancellationToken cancellationToken) { CheckConnection(); return RetryRequest( - async () => await _runServiceHttpClient.CompleteJobAsync(requestUri, planId, jobId, result, outputs, stepResults, jobAnnotations, cancellationToken), cancellationToken); + async () => await _runServiceHttpClient.CompleteJobAsync(requestUri, planId, jobId, result, outputs, stepResults, jobAnnotations, environmentUrl, cancellationToken), cancellationToken); } public Task RenewJobAsync(Guid planId, Guid jobId, CancellationToken cancellationToken) diff --git a/src/Runner.Listener/JobDispatcher.cs b/src/Runner.Listener/JobDispatcher.cs index 9dbf7ddcc..f1b4af9eb 100644 --- a/src/Runner.Listener/JobDispatcher.cs +++ b/src/Runner.Listener/JobDispatcher.cs @@ -1177,7 +1177,7 @@ namespace GitHub.Runner.Listener jobAnnotations.Add(unhandledAnnotation.Value); } - await runServer.CompleteJobAsync(message.Plan.PlanId, message.JobId, TaskResult.Failed, outputs: null, stepResults: null, jobAnnotations: jobAnnotations, CancellationToken.None); + await runServer.CompleteJobAsync(message.Plan.PlanId, message.JobId, TaskResult.Failed, outputs: null, stepResults: null, jobAnnotations: jobAnnotations, environmentUrl: null, CancellationToken.None); } catch (Exception ex) { diff --git a/src/Runner.Worker/JobRunner.cs b/src/Runner.Worker/JobRunner.cs index 5e3db1e67..5d99f6a48 100644 --- a/src/Runner.Worker/JobRunner.cs +++ b/src/Runner.Worker/JobRunner.cs @@ -7,6 +7,7 @@ using System.Net.Http.Headers; using System.Text; using System.Threading; using System.Threading.Tasks; +using GitHub.DistributedTask.ObjectTemplating.Tokens; using GitHub.DistributedTask.Pipelines; using GitHub.DistributedTask.WebApi; using GitHub.Runner.Common; @@ -283,6 +284,13 @@ namespace GitHub.Runner.Worker // Make sure we don't submit secrets as telemetry MaskTelemetrySecrets(jobContext.Global.JobTelemetry); + // Get environment url + string environmentUrl = null; + if (jobContext.ActionsEnvironment?.Url is StringToken urlStringToken) + { + environmentUrl = urlStringToken.Value; + } + Trace.Info($"Raising job completed against run service"); var completeJobRetryLimit = 5; var exceptions = new List(); @@ -290,7 +298,7 @@ namespace GitHub.Runner.Worker { try { - await runServer.CompleteJobAsync(message.Plan.PlanId, message.JobId, result, jobContext.JobOutputs, jobContext.Global.StepsResult, jobContext.Global.JobAnnotations, default); + await runServer.CompleteJobAsync(message.Plan.PlanId, message.JobId, result, jobContext.JobOutputs, jobContext.Global.StepsResult, jobContext.Global.JobAnnotations, environmentUrl, default); return result; } catch (Exception ex) diff --git a/src/Sdk/RSWebApi/Contracts/CompleteJobRequest.cs b/src/Sdk/RSWebApi/Contracts/CompleteJobRequest.cs index 00b3a1002..fff5156a4 100644 --- a/src/Sdk/RSWebApi/Contracts/CompleteJobRequest.cs +++ b/src/Sdk/RSWebApi/Contracts/CompleteJobRequest.cs @@ -26,5 +26,8 @@ namespace GitHub.Actions.RunService.WebApi [DataMember(Name = "annotations", EmitDefaultValue = false)] public IList Annotations { get; set; } + + [DataMember(Name = "environmentUrl", EmitDefaultValue = false)] + public string EnvironmentUrl { get; set; } } } diff --git a/src/Sdk/RSWebApi/RunServiceHttpClient.cs b/src/Sdk/RSWebApi/RunServiceHttpClient.cs index 3098f8350..bafcee5aa 100644 --- a/src/Sdk/RSWebApi/RunServiceHttpClient.cs +++ b/src/Sdk/RSWebApi/RunServiceHttpClient.cs @@ -100,6 +100,7 @@ namespace GitHub.Actions.RunService.WebApi Dictionary outputs, IList stepResults, IList jobAnnotations, + string environmentUrl, CancellationToken cancellationToken = default) { HttpMethod httpMethod = new HttpMethod("POST"); @@ -110,7 +111,8 @@ namespace GitHub.Actions.RunService.WebApi Conclusion = result, Outputs = outputs, StepResults = stepResults, - Annotations = jobAnnotations + Annotations = jobAnnotations, + EnvironmentUrl = environmentUrl, }; requestUri = new Uri(requestUri, "completejob"); diff --git a/src/Test/L0/Worker/JobRunnerL0.cs b/src/Test/L0/Worker/JobRunnerL0.cs index ce70b8eb4..d4aaf809c 100644 --- a/src/Test/L0/Worker/JobRunnerL0.cs +++ b/src/Test/L0/Worker/JobRunnerL0.cs @@ -99,7 +99,8 @@ namespace GitHub.Runner.Common.Tests.Worker timeline, jobId, testName, - testName, null, null, null, new Dictionary(), new List(), new Pipelines.JobResources(), new Pipelines.ContextData.DictionaryContextData(), new Pipelines.WorkspaceOptions(), new List(), null, null, null, null, + testName, null, null, null, new Dictionary(), new List(), new Pipelines.JobResources(), new Pipelines.ContextData.DictionaryContextData(), new Pipelines.WorkspaceOptions(), new List(), null, null, null, + new ActionsEnvironmentReference("staging"), messageType: messageType); message.Variables[Constants.Variables.System.Culture] = "en-US"; message.Resources.Endpoints.Add(new ServiceEndpoint()