Runner policy enforceable job cleanup for all executor types

Summary

User wants to be be able to configure specific runners to clean up job work dir before/after job in that way that it cannot be overridden in the project config. Whether we do this with a FF or some other mechanism is up for discussion.

Proposal

  1. FF_ENABLE_JOB_CLEANUP feature flag (disabled by default) should always run when set to true. Regardless whether the job succeeds, is canceled or fails.
  2. The FF should run the same for all Runner executors
  3. The FF behavior should remain as described in the related issue

I.e. being able to:

  1. Force FF_ENABLE_JOB_CLEANUP
  2. Override the default OS cleanup command for Linux and Windows

This is currently only possible when:

  1. The FF_ENABLE_JOB_CLEANUP FF is enabled in the Runner config.toml
  2. GIT_STRATEGY: clone is set
    1. In the project Settings -> CI/CD -> General pipelines
    2. In the .gitlab-ci.yml or included pipeline template file as a CI variable

NOTE: FF FF_USE_WINDOWS_LEGACY_PROCESS_STRATEGY does not have an effect on the outcome and was used for testing different scenarios. Only GIT_STRATEGY: clone allows CI_PROJECT_DIR cleanup BEFORE and AFTER the job. Without it set NO cleanup occurs.

Happy medium solution

#29446 (comment 1181890313)

Current behavior

When only configuring the FF_ENABLE_JOB_CLEANUP FF in the Runner config.toml, w/ Git strategy set to fetch (as default), the outcome is no folders cleaned

CI_PROJECT_DIR

CI_PROJECT_DIR

CI_PROJECT_DIR files

clean_fail

Expected behavior

The FF_ENABLE_JOB_CLEANUP FF cleans/removes the CI_PROJECT_DIR after the job, regardless whether Git strategy is set to fetch or clone.

CI_PROJECT_DIR .tmp folder remaining file (without Git data or any secrets)

clean_success_residue

Edited by Darren Eastman