Set GIT_DEPTH in runtime

I want to set GIT_DEPTH to results of different expressions in different jobs. It may be count of commits from create branch or result of arithmetic expression. But I can’t set variable to expression, like

  GIT_DEPTH: $(if [ $"CI_COMMIT_REF_NAME" == "master" ]; then 1; fi)

  stage: build
    - echo $GIT_DEPTH

Here is anybody who know about how it works?

I am not an expert, but I believe this is not possible in the variables: section.

You might wanna use the before_script or the script section.