Skip to content

Expose source branch protected and squash CI vars

What does this MR do and why?

Adds two new Merge request variables:

  • CI_MERGE_REQUEST_SOURCE_BRANCH_PROTECTED : whether the source branch is protected or not.
  • CI_MERGE_REQUEST_SQUASH_ON_MERGE: whether the squash on merge option has been set, either forced by project settings or enabled in the Merge Request itself.

Use case

We want a job to only run when both the source and the target branch of the Merge Request are protected and the squash option is enabled.

Currently we are not able to detect these conditions with the rules keyword because we miss in the information this contribution is aiming to add.

Screenshots or screen recordings

CI_MERGE_REQUEST_SOURCE_BRANCH_PROTECTED: !127848 (comment 1501184344)

CI_MERGE_REQUEST_SQUASH_ON_MERGE: !127848 (comment 1501266446)

How to set up and validate locally

Create a simple job:

testing-the-variables:
  rules:
    - if: "$CI_PIPELINE_SOURCE =='merge_request_event'"
  script:
    - echo "CI_MERGE_REQUEST_SOURCE_BRANCH_PROTECTED = $CI_MERGE_REQUEST_SOURCE_BRANCH_PROTECTED"
    - echo "CI_MERGE_REQUEST_SQUASH_ON_MERGE = $CI_MERGE_REQUEST_SQUASH_ON_MERGE"

The values should represent the settings you have set for the branch and the Merge Request.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Tyrone Meijn

Merge request reports