Skip to content

Handle transition from cancelling to cancelled

Problem

We want to allow after_script to run when a build is cancelled. Currently the runner does not support running the after_script when the build is cancelled or uploading artifacts:

A change is required in the Runner to upload artifacts to GitLab in scenarios where the build is canceled. And to run the after_script when the build is cancelled.

Step Issue
Runner, Step 1 #30827 (closed) <- You are here
Backend, Step 2 gitlab#399215 (closed)
Backend, Step 3 gitlab#399296 (closed)
Feature Flag Rollout gitlab#399302 (moved)

Proposal

Discussion about approach in MR

Full flow (runner and rails)

When the runner receives canceling status (Full flow from runner to rails):

  1. as usual, if the job is in a status other than running that is not a COMPLETED_STATUS (%w[success failed canceled skipped])
  • Gitlab rails will transition it directly to canceled and update the job to Gitlab.
  • The runner will not execute after_script and no traces/artifacts should be uploaded.
  1. if the job is running
  • Gitlab rails will send a cancelling status
  • Gitlab runner will abort the scripts, run the after_script and upload traces/artifacts.
  • When Gitlab runner is finished running the work in after_script, it will send a canceled status which will allow gitlab rails to update the jobs
  1. Placeholder: Ensure runner compatibility strategy
  • We can use the cancel_gracefully runner feature name.
  • Can we revert to the old behavior on the rails side if no runners are available with this feature?

Runner changes for this issue

When canceling status is received the runner should run the after_script and upload traces/artifacts, then it should send a cancelled status to GitLab rails.

Edited by Allison Browne