mirror of
https://github.com/actions/runner.git
synced 2025-12-13 19:03:44 +00:00
Runner Job Started/Completed Hooks (#1737)
* Prototype for pre job hook * Remove debug log * Enable hooks again * Initialize with hostContext * Add event_path, fix no-path bug * Allow script post steps * Call script handler with correct pre post stage * Add job completed hook * Make filecommand work and hardcode shell * Conditionally print step details and no telemetry for hooks * Figure out whih script to use * Only check path for managed scripts * Resture win dependency * Nits * Remove unused, add named params * Telemetry + refactoring * add message to job * rename hooks remove stale comment * cleanup * Use .CreateService to create step * Add L0s * pr feedback * update tests * add disclaimer, clean up code * spacing fix * little more cleanup * pr fix * pr feedback * Refactor to use JobExtension * fix tests * fix typo * cleanup code * more cleanup * little more cleanup * last bit of cleanup * fix tests * nit fix * Update src/Runner.Worker/JobHookProvider.cs Co-authored-by: Edward Thomson <ethomson@github.com> * don't override runner telemtry * pr feedback * pr feedback * pr feedback Co-authored-by: Thomas Boop <thboop@github.com> Co-authored-by: Thomas Boop <52323235+thboop@users.noreply.github.com> Co-authored-by: Edward Thomson <ethomson@github.com>
This commit is contained in:
@@ -15,6 +15,7 @@ using GitHub.DistributedTask.WebApi;
|
||||
using GitHub.Runner.Common;
|
||||
using GitHub.Runner.Common.Util;
|
||||
using GitHub.Runner.Sdk;
|
||||
using GitHub.Runner.Worker;
|
||||
using Pipelines = GitHub.DistributedTask.Pipelines;
|
||||
|
||||
namespace GitHub.Runner.Worker
|
||||
@@ -248,6 +249,19 @@ namespace GitHub.Runner.Worker
|
||||
Trace.Info("Downloading actions");
|
||||
var actionManager = HostContext.GetService<IActionManager>();
|
||||
var prepareResult = await actionManager.PrepareActionsAsync(context, message.Steps);
|
||||
|
||||
// add hook to preJobSteps
|
||||
var startedHookPath = Environment.GetEnvironmentVariable("ACTIONS_RUNNER_HOOK_JOB_STARTED");
|
||||
if (!string.IsNullOrEmpty(startedHookPath))
|
||||
{
|
||||
var hookProvider = HostContext.GetService<IJobHookProvider>();
|
||||
var jobHookData = new JobHookData(ActionRunStage.Pre, startedHookPath);
|
||||
preJobSteps.Add(new JobExtensionRunner(runAsync: hookProvider.RunHook,
|
||||
condition: $"{PipelineTemplateConstants.Always}()",
|
||||
displayName: Constants.Hooks.JobStartedStepName,
|
||||
data: (object)jobHookData));
|
||||
}
|
||||
|
||||
preJobSteps.AddRange(prepareResult.ContainerSetupSteps);
|
||||
|
||||
// Add start-container steps, record and stop-container steps
|
||||
@@ -337,6 +351,18 @@ namespace GitHub.Runner.Worker
|
||||
}
|
||||
}
|
||||
|
||||
// Register Job Completed hook if the variable is set
|
||||
var completedHookPath = Environment.GetEnvironmentVariable("ACTIONS_RUNNER_HOOK_JOB_COMPLETED");
|
||||
if (!string.IsNullOrEmpty(completedHookPath))
|
||||
{
|
||||
var hookProvider = HostContext.GetService<IJobHookProvider>();
|
||||
var jobHookData = new JobHookData(ActionRunStage.Post, completedHookPath);
|
||||
jobContext.RegisterPostJobStep(new JobExtensionRunner(runAsync: hookProvider.RunHook,
|
||||
condition: $"{PipelineTemplateConstants.Always}()",
|
||||
displayName: Constants.Hooks.JobCompletedStepName,
|
||||
data: (object)jobHookData));
|
||||
}
|
||||
|
||||
List<IStep> steps = new List<IStep>();
|
||||
steps.AddRange(preJobSteps);
|
||||
steps.AddRange(jobSteps);
|
||||
|
||||
Reference in New Issue
Block a user