LoginSignup
1

More than 5 years have passed since last update.

Gitlabのサーバサイドフックでユーザ名を得る

Posted at

はじめに

以前Gitlabのサーバサイドフックでユーザ情報を得るという記事を書きました。
サーバサイドフックから環境変数GL_IDでユーザIDを得られる、という内容でしたが
Gitlab10.1よりユーザ名を直接得られるようになりましたのでアップデートしておきます。

環境変数GL_USERNAME

こちらのMRにて環境変数GL_USERNAMEが追加されました。
ユーザadminだけmasterブランチにpushできるupdateスクリプトの例を示します。

#!/bin/bash

branch="$1"

if [ "$branch" == "refs/heads/master" ]; then
    if [ "$GL_USERNAME" == "admin" ]; then
        exit 0
    else
        echo "-------------------------------------"
        echo "[$branch] is protected"
        echo "-------------------------------------"
        exit 1
    fi
fi

exit 0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1