Chapter 4. Repository Hooks

In Business Central, it is possible to trigger a chosen action every time a particular event happens. For this purpose, you can configure the repository to use scripts called hooks.

4.1. Configuring Git Hooks

Business Central can automatically push changes to a remote repository using the Git hooks. Git hooks support has been introduced with the release of Red Hat JBoss BPM Suite 6.2.0.

Note

Please note that currently only the post-commit hook is supported. Post-commit hooks are triggered after finishing the entire commit process.

The following procedure shows how to configure the post-commit hook to automatically push your changes to the remote repository.

  1. In Business Central, go to AuthoringAdministration.
  2. Below the main menu, click RepositoriesClone repository.
  3. In the displayed Clone repository dialog box, fill in the repository information:

    • Repository Name
    • Organizational Unit
    • Git URL: For example https://github.com/USERNAME/REPOSITORY_NAME.git

      Important

      It is important to use the HTTPS or Git protocol instead of a SCP-style SSH URL. Business Central does not support the basic SSH URL and fails with Invalid URL format.

      Figure 4.1. An invalid SCP-style SSH URL.

      An invalid SCP-style SSH URL.
    • User Name: your Git user name
    • Password: your Git password
  4. Change to the created repository:

    cd JBOSS_HOME/bin/.niogit/REPOSITORY_NAME.git
  5. Change the remote URL:

    git remote set-url origin git@github.com:USERNAME/REPOSITORY_NAME.git

    Make sure that you can access the remote repository through command line using SSH. For example, the private SSH key for the repository should exist under the ~/.ssh/ directory.

    If you created a new repository, you may encounter the following error:

    fatal: No such remote 'origin'

    To resolve it, add the remote origin URL:

    git remote add origin git@github.com:USERNAME/REPOSITORY_NAME.git
  6. Verify that the remote repository was successfully added:

    git remote -v

    The command should list the following:

    origin  git@github.com:USERNAME/REPOSITORY_NAME.git (fetch)
    origin  git@github.com:USERNAME/REPOSITORY_NAME.git (push)
  7. Create a file named post-commit with the permissions set to rwxr--r-- under JBOSS_HOME/bin/.niogit/REPOSITORY_NAME.git/hooks with the following content:

    #!/bin/sh
    git push origin master
  8. Make sure that the configuration was successful by creating a new guided rule in Business Central:

    1. Go to AuthoringProject AuthoringNew ItemGuided Rule.
    2. Fill in the required information in the displayed Create new Guided Rule window.
    3. Click Ok.

All of the changes should be pushed automatically.

For further information about remote Git repositories, see How to configure the BxMS 6 server to use a remote Git repository for storing assets?.

It is also possible to specify the system property org.uberfire.nio.git.hooks. Its value determines a directory with default hook files, which will be copied to the newly created Git repositories. See the example of a standalone.xml file with this setting below:

<system-properties>
  <property name="org.uberfire.nio.git.hooks" value="/opt/jboss-as/git-hooks">
  </property>
  ...
</system-properties>