Are there variables available in the Bash environment for server side hooks?

In Github there are environment variables like GITHUB_VIA that expose the action that originated a git commit. In the example below, taken from here, this is used to protect default branches.

Is there something similar for Gitlab? I’m coding a pre-receive hook and I can’t find this documented anywhere on Gitlab’s doc.

#!/bin/bash
#
# This hook restricts changes on the default branch to those made with the GUI Pull Request Merge button, or the Pull Request Merge API.
#
DEFAULT_BRANCH=$(git symbolic-ref HEAD)
while read -r oldrev newrev refname; do
  if [[ "${refname}" != "${DEFAULT_BRANCH:=refs/heads/master}" ]]; then
    continue
  else
    if [[ "${GITHUB_VIA}" != 'pull request merge button' && \
          "${GITHUB_VIA}" != 'pull request merge api' ]]; then
      echo "Changes to the default branch must be made by Pull Request. Direct pushes, edits, or merges are not allowed."
      exit 1
    else
      continue
    fi
  fi
done

I’m looking for environment variables I could use within the context of a pre-receive on Gitlab, such as these ones on GHE.

Hi @AbelAlejandro I think you’re looking for this page in the docs

Thanks @snim2 but that’s not what I was looking for.

What I was searching was somewhere else.

It makes sense because it’s not something users will be worrying about.

1 Like

Ah, right! Glad you found the right docs.

1 Like