Deploying post-receive hooks in GitLab

You can configure post-receive hooks for linking work items to Git commits.

About this task

On Linux, the Git repositories are located by default under /var/opt/gitlab/git-data/repositories. The following steps assume that the GitLab repositories are in this location. Repeat this task for each Git repository. If there are existing hook scripts, manually merge the new scripts with the existing ones.

Procedure

  1. Create a folder named custom_hooks under /var/opt/gitlab/git-data/repositories/repository-name.
  2. Copy the post-receive hook file from EWM-git-integration-toolkit-install-folder/server/hooks/examples/gitlab/post-receive to /var/opt/gitlab/git-data/repositories/repository-name/custom_hooks.
  3. Assign executable permission to the file: chmod +x post-receive
  4. Open the post-receive file in a text editor.
  5. Uncomment and set the following mandatory variables:
    Variable Description
    RTC_GIT_SERVER_TOOLKIT_PATH Absolute path to the folder where the EWM Git Integration Toolkit has been installed.
    GL_TOKEN Personal access token of a GitLab user.
    GL_SERVER The URL of the GitLab server.
    GL_INFO_FILE

    Instead of providing the values of GL_TOKEN and GL_SERVER, you can add those values to a file and provide the path to the file. For instance, in Linux, create a file under /opt/rtc-gitlab/tokenfile with the following content:

    GL_TOKEN=<replace with token generated from gitlab> 
    GL_SERVER=http://localhost

    Then set the value for GL_INFO_FILEto /opt/rtc-gitlab/tokenfile.

    You can also uncomment and set the following optional variables:
    Variable Description
    NODE_EXECUTABLE

    Optional: Absolute path to the node executable. Required if node executable cannot be found in the system path.

    Uncomment and set the absolute path of the directory where EWM Git Integration toolkit is installed. This is usually set by the Node.js server.

    RTC_GIT_SERVER_TRACE_LEVEL Optional: Logging level for the hooks. Set this value to 4 while you set up the integration. Revert it after you validate the integration.
    REMOTE_USER Optional: If IBM® Engineering Workflow Management (EWM) and GitLab do not share a common user base, then provide a functional user ID. This user ID should be a valid EWM user.
    VERIFY_GITLAB_SSL_CERT Optional: Set the value to true if the GitLab server's certificate should be validated by the hook. Otherwise, set to false. The default is true. This option applies only if the GitLab server is configured with HTTPS.
    Note:

    The following environment variables are mandatory:

    • RTC_GIT_SERVER_TOOLKIT_PATH
    • RTC_GIT_SERVER_TRACE_LEVEL
    • GL_TOKEN
    • GL_SERVER
  6. Set the Git configuration properties user.name and user.email for the operating system user who owns the GitLab process.