Deploying the receive hook for Gerrit

Registering your Gerrit project with the Git adapter allows users to add links from Gerrit changes to Rational Team Concert™ work items from Gerrit. Users add links with the Add Link option that is provided on the Rational® Adapter for Git banner. To add links to work items automatically when users push changes to the shared Git repository, you must deploy the Rational Adapter for Git receive hook.

Before you begin

The Git adapter receive hook requires the Perl 5.10.1 software and these Perl modules:
Important: Some Linux distributions do not include some Perl core modules in their default Perl installation. You must install the full Perl core. The Git adapter receive hook depends on the Time packages and the Crypt package. Although these packages are not included by default in the RHEL 6 distribution, you can add them using these commands:
yum install perl-Time-*
yum install perl-Crypt-SSLeay

About this task

You use the receive hook for Gerrit to process changes pushed to the shared Git repository and associate these changes to existing Rational Team Concert work items.

A script gerrit_setup.sh is provided to help you install and configure the receive hook. You must set the information about how to connect to the Git adapter with either the script gerrit_setup.sh or with git config.

The receive hook for Gerrit is patchset-created.

Procedure

  1. To install the Gerrit receive hook, from the ./static folder that is found in the root of the Gerrit server directory, run gerrit_setup.sh with the --hook command.

    The --hook command takes four optional parameters that you can use to set the information about how to connect to the Git adapter. These parameters are --username, --password, --jts_url, and --adapter_project_url. You specify these optional parameters for a Git repository by setting the parameter --repo_dir along with these optional parameters. For more information about these parameters, run gerrit_setup.sh --help in the static folder of the Gerrit server directory.

    Tip: You can run the gerrit_setup.sh script without defining a command and its parameters. The gerrit_setup.sh script when first run, prompts you for the command, either -i to deploy the Gerrit additions, -r to register the Gerrit server, or --hook to deploy the receive hook for Gerrit.

    Run one of these commands:

    ./static/gerrit_setup.sh --hook 
    ./static/gerrit_setup.sh --hook --repo_dir /git_repos/gerrit/first --username clmuser --password clmuserpassword --jts_url https://my.server.com:9443/jts --adapter_project_url https://my.server.com:9443/gitAdapter/adapted-project/0_1/my_project
  2. If you did not set the information about how to connect to the Git adapter with gerrit_setup.sh, you can set rtc.user, rtc.password, rtc.jtsURL, and rtc.gerritAdaptedProjectURL in the Git configuration.
    Important:
    • The user ID, password, and JTS URL can be in a Git configuration level that is shared across several repositories. However, the adapted project URI must be configured uniquely for each Git repository. The adapted project URI is the URI you were given when you registered the project from Gerrit.
    • Review the information about the Git adapter receive hook user, see Adapter users.

    Set the following Git config parameters for the specific repository under a Gerrit server. From the command line, go to the shared repository and type the following commands:

    git config rtc.gerritAdaptedProjectURL https://your-host:port/gitAdapter/adapted-project/1/0_2/first.git 
    git config rtc.jtsURL https://your-host:port/jts 
    git config rtc.user username 
    git config rtc.password password 
  3. Restart the Gerrit server to activate the hooks.

What to do next

Hide the Git adapter banner for unregistered projects, see Hiding the Git adapter banner on unregistered projects (optional).

Feedback