Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send environment url to Run Service #2650

Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Runner.Common/RunServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Task CompleteJobAsync(
Dictionary<String, VariableValue> outputs,
IList<StepResult> stepResults,
IList<Annotation> jobAnnotations,
string environmentUrl,
CancellationToken token);

Task<RenewJobResponse> RenewJobAsync(Guid planId, Guid jobId, CancellationToken token);
Expand Down Expand Up @@ -70,11 +71,12 @@ public Task CompleteJobAsync(
Dictionary<String, VariableValue> outputs,
IList<StepResult> stepResults,
IList<Annotation> 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<RenewJobResponse> RenewJobAsync(Guid planId, Guid jobId, CancellationToken cancellationToken)
Expand Down
2 changes: 1 addition & 1 deletion src/Runner.Listener/JobDispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1177,7 +1177,7 @@ private async Task ForceFailJob(IRunnerService server, Pipelines.AgentJobRequest
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: "", CancellationToken.None);
heavymachinery marked this conversation as resolved.
Show resolved Hide resolved
}
catch (Exception ex)
{
Expand Down
10 changes: 9 additions & 1 deletion src/Runner.Worker/JobRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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;
Expand Down Expand Up @@ -283,14 +284,21 @@ private async Task<TaskResult> CompleteJobAsync(IRunServer runServer, IExecution
// Make sure we don't submit secrets as telemetry
MaskTelemetrySecrets(jobContext.Global.JobTelemetry);

// Get environment url
var environmentUrl = "";
heavymachinery marked this conversation as resolved.
Show resolved Hide resolved
if (jobContext?.ActionsEnvironment?.Url is StringToken urlStringToken)
heavymachinery marked this conversation as resolved.
Show resolved Hide resolved
{
environmentUrl = urlStringToken.Value;
}

Trace.Info($"Raising job completed against run service");
var completeJobRetryLimit = 5;
var exceptions = new List<Exception>();
while (completeJobRetryLimit-- > 0)
{
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)
Expand Down
3 changes: 3 additions & 0 deletions src/Sdk/RSWebApi/Contracts/CompleteJobRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@ public class CompleteJobRequest

[DataMember(Name = "annotations", EmitDefaultValue = false)]
public IList<Annotation> Annotations { get; set; }

[DataMember(Name = "environmentUrl", EmitDefaultValue = false)]
public string EnvironmentUrl { get; set; }
}
}
4 changes: 3 additions & 1 deletion src/Sdk/RSWebApi/RunServiceHttpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public async Task CompleteJobAsync(
Dictionary<String, VariableValue> outputs,
IList<StepResult> stepResults,
IList<Annotation> jobAnnotations,
string environmentUrl,
CancellationToken cancellationToken = default)
{
HttpMethod httpMethod = new HttpMethod("POST");
Expand All @@ -110,7 +111,8 @@ public async Task CompleteJobAsync(
Conclusion = result,
Outputs = outputs,
StepResults = stepResults,
Annotations = jobAnnotations
Annotations = jobAnnotations,
EnvironmentUrl = environmentUrl,
};

requestUri = new Uri(requestUri, "completejob");
Expand Down
3 changes: 2 additions & 1 deletion src/Test/L0/Worker/JobRunnerL0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ private Pipelines.AgentJobRequestMessage GetMessage(String messageType = JobRequ
timeline,
jobId,
testName,
testName, 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,
testName, 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,
new ActionsEnvironmentReference("staging"),
messageType: messageType);
message.Variables[Constants.Variables.System.Culture] = "en-US";
message.Resources.Endpoints.Add(new ServiceEndpoint()
Expand Down