Ensure after_script is called for canceled jobs
### Release notes
When a user cancels a pipeline the `after_script` portion of jobs currently running will always be executed.
### Opt Out Details
Please see https://docs.gitlab.com/ci/yaml/script/#skip-after_script-commands-if-a-job-is-canceled on how to opt-out of the change.
### Problem to Solve
It's possible to want a `after_script` step for a gitlab-ci.yml, where it's important that it always run. However, the current behavior of `after_script` is that if a build is **canceled** the cleanup stage is skipped (even though this does not appear to be the original intent: https://gitlab.com/gitlab-org/gitlab-ci-multi-runner/issues/102#note_11619214).
### Proposal
**Runner, Step 1**
When the runner receives `canceling` status and job config `when: always` is set:
- as usual, if the job is in either `created` or `pending`, it should transit directly to `canceled` and update the job to Gitlab. No `after_script` should be executed or no traces/artifacts should be uploaded.
- if the job is `running`, it will abort the scripts, run the `after_script` and upload traces/artifacts. Once all is finished, it will transit to `canceled` and update the job to Gitlab
**Backend, Step 2**
- introduce the `canceling` status **Frontend**
- when the job is in `canceling` state, allow traces/artifacts to be uploaded only when `when: always` is set
The main Cancel :x: button on the Pipelines page should be a button for a graceful shutdown if `when: always`.
**Backend, Step 3**
- when graceful cancel button is click, job should transit to `canceling`.
| Step | Group | Issue |
|------|-------|-------|
| Runner, Step 1 | ~"group::runner" | https://gitlab.com/gitlab-org/gitlab-runner/-/issues/30827 |
| Backend, Step 2 | ~"group::pipeline execution" | https://gitlab.com/gitlab-org/gitlab/-/issues/399215 |
| Backend, Step 3 | ~"group::pipeline execution" | https://gitlab.com/gitlab-org/gitlab/-/issues/399296 |
| Feature Flag Rollout | ~"group::pipeline execution" | https://gitlab.com/gitlab-org/gitlab/-/issues/399302 |
### Intended users
* [Sasha (Software Developer)](https://about.gitlab.com/handbook/marketing/product-marketing/roles-personas/#sasha-software-developer)
* [Devon (DevOps Engineer)](https://about.gitlab.com/handbook/marketing/product-marketing/roles-personas/#devon-devops-engineer)
### User experience goal
When a user cancels a pipeline/job the `after_script` portion of jobs currently running should be executed.
### Permissions and Security
* [ ] Add expected impact to members with no access (0)
* [ ] Add expected impact to Guest (10) members
* [x] Add expected impact to Reporter (20) members
* [x] Add expected impact to Developer (30) members
* [x] Add expected impact to Maintainer (40) members
* [x] Add expected impact to Owner (50) members
### Documentation
* This will require an update to the [`after_script`](https://docs.gitlab.com/ee/ci/yaml/#after_script) section of the docs.
### Availability & Testing
### What does success look like, and how can we measure that?
### Links / references
* This issue was split from https://gitlab.com/gitlab-org/gitlab/-/issues/15603+
* A POC was created and reviewed in this issue: https://gitlab.com/gitlab-org/gitlab/-/issues/361502+
_This page may contain information related to upcoming products, features and functionality. It is important to note that the information presented is for informational purposes only, so please do not rely on the information for purchasing or planning purposes. Just like with all projects, the items mentioned on the page are subject to change or delay, and the development, release, and timing of any products, features, or functionality remain at the sole discretion of GitLab Inc._
<!-- triage-serverless v3 PLEASE DO NOT REMOVE THIS SECTION -->
*This page may contain information related to upcoming products, features and functionality.
It is important to note that the information presented is for informational purposes only, so please do not rely on the information for purchasing or planning purposes.
Just like with all projects, the items mentioned on the page are subject to change or delay, and the development, release, and timing of any products, features, or functionality remain at the sole discretion of GitLab Inc.*
<!-- triage-serverless v3 PLEASE DO NOT REMOVE THIS SECTION -->
epic