Add support to GitLab Runner for the Run `after_script` when job is `canceling` feature
Status update (2024-04-11)
Please follow the epic Ensure after_script is called for canceled jobs for the latest implementation plan and schedule.
Overview
This is the runner work to implement Ensure after_script is called for canceled jobs and has all the technical details and work that we need to do on the runner to implement this.
Note: This issue will implement the required changes in GitLab Runner that are a pre-requisite to the release of the user facing feature in GitLab CI. Users interested in using this feature in GitLab CI should follow the related user-facing issue.
Note: Please see the Tasks section for what needs to be done.
Proposal
graph TD
job[running job] --> trace[update job trace]
trace --> jobStatus{job status response from rails}
jobStatus -->|cancelling| puase[stop user script and anything that comes before it]
puase --> after_script
after_script --> status[send job status update to be `canceled`]
status --> finish
jobStatus -->|cancelled| finish[stop everything and run cleanup]
- runner will send a new feature that supports the
cancelingjob status. - runner will send the
canceledjob status when it's finished - When runners get the
canceledjob status it will behave as it is now, aborting the build and stop everything.
Sequencing
- Add support for
cancelingstate. - Run
after_scriptwhen job status is incancelingstate. - Introduce
CI_JOB_STATUSto tell the user ofafter_scriptat which stage they are in. This will allow users to opt out from runningafter_scripton canceling jobs in case the feature flag is turned on. This is done in !2342 (merged)
Edited by Darren Eastman