Skip to content

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]
  1. runner will send a new feature that supports the canceling job status.
  2. runner will send the canceled job status when it's finished
  3. When runners get the canceled job status it will behave as it is now, aborting the build and stop everything.

Sequencing

  1. Add support for canceling state.
  2. Run after_script when job status is in canceling state.
  3. Introduce CI_JOB_STATUS to tell the user of after_script at which stage they are in. This will allow users to opt out from running after_script on canceling jobs in case the feature flag is turned on. This is done in !2342 (merged)
Edited by Darren Eastman