-
Notifications
You must be signed in to change notification settings - Fork 1k
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
[self-hosted] A hook that is fired before job starts #1543
Comments
Yeah, I can understand where you're coming from - do you have other work that you want to perform in this hook, or is it really just cleaning up the workdir? I ask because maybe there's an option to always clean the workdir instead of always running a hook. 🤔 |
Not affiliated with @gajus, but I believe a pre-job hook would work well for our organization as well. Our runners are ephemeral, launched into a "warm pool" of registered runners via an AWS Auto Scaling Group. We don't need to do any cleanup, but would use the hook to detach the instance from the pool once it picks up a job so that it can be replaced by a new one. Currently we do this with a background loop checking for the worker process (as below), but a supported while true; do
WORKER_PROC=$( pgrep -P "$(pgrep Runner.Listener)" Runner.Worker )
if [[ -n "$WORKER_PROC" ]]; then
echo "Detaching from ASG..."
INSTANCE_ID=$(ec2metadata --instance-id)
ASG_NAME=$( aws autoscaling describe-auto-scaling-instances \
--instance-ids "$INSTANCE_ID" \
--query 'AutoScalingInstances[0].AutoScalingGroupName' --output text )
aws autoscaling detach-instances \
--instance-ids "$INSTANCE_ID" \
--auto-scaling-group-name "$ASG_NAME" \
--no-should-decrement-desired-capacity
break
fi
sleep 2
done |
We ended up tapping into logs. |
Sorry, I just noticed the question – It's mostly clean up, but we are now considering pre-populating directory with repository specific build tools too. The approach of tapping into logs works Okay, but it is super hacky. |
@ethomson An alternative that I would really appreciate is if there was a way to prepend GitHub Actions steps to every workflow running on the machine. |
We have the exact same requirement, where we need to ensure a runner is in a clean state before a new job can start execution. Perhaps a post-job hook would be slightly better for this use case since the new job does not have to wait for cleanup? @ethomson would you be able to elaborate on the alternative option that you have mentioned? |
Cleanup (for root owned files) is our use case. What is that option, @ethomson ?
|
We recently published an ADR for Job Started / Job Completed hooks for self hosted runners, feel free to provide your feedback. In particular we would love to hear what (if anything ) else you would need to support your use case, and if the interface makes sense for you. |
Closing this as a dupe of #699 |
We are using the self-hosted runners and we would like to perform various clean up jobs before every job, e.g. cleaning up the workdir. Is there any hook / event that we could subscribe to?
The text was updated successfully, but these errors were encountered: