Context
On GitLab, squash enforcement has to go through CI, because the native setting applies to the whole project. In Settings → Merge requests → Squash commits when merging , the Require option would also squash the develop → master release MRs, which must keep their history.
GitLab does have an advantage over GitHub: every MR carries a "Squash commits when merge request is accepted" checkbox, readable in CI through CI_MERGE_REQUEST_SQUASH_ON_MERGE and editable through the API. The three options below rely on jobs that only run for MRs into develop .
Shared prerequisite: enable Pipelines must succeed ( Settings → Merge requests ). Without it, a failed job shows a red cross but does not prevent the merge. Squashing must also be allowed (not set to "Do not allow").
Option 1 — Block when the squash box is unticked
The job reads the checkbox when the pipeline starts and fails if it is not ticked.…