第19章 Git hooks and remote Git repository integration

Git hooks are bash scripts that execute before or after Git events such as git commit or git push. In Business Central, you can use Git hooks to configure repositories to trigger specified actions every time events happen. For more information about Git hooks, see Customizing Git Hooks.

You can integrate remote Git repositories with Business Central by using post-commit Git hooks. This enables you to automate content replication between Business Central and remote repositories. For example, you can implement a real-time backup strategy where changes you make to your Business Central projects are replicated to your remote Git repositories.

注記

Business Central only supports post-commit Git hooks.

A post-commit Git hook executes after every commit as a sync operation. Business Central waits for the post-commit bash to complete and no other write operation occurs in the repository.

19.1. Creating post-commit Git hooks

You can create a post-commit Git hook bash script file that executes code contained in that file or execute code from a different file such as a Java program.

Procedure

  1. Create a post-commit Git hook file:

    $ touch post-commit
  2. Set the permissions of the post-commit file to 755:

    $ chmod 755 post-commit
  3. Add #!/bin/bash and any required code to the post-commit file, for example:

    • To push all changes to a remote repository:

      #!/bin/bash
      git push origin +master
    • To log a message:

      #!/bin/bash
      echo 'Hello World'
    • To execute code of another file:

      #!/bin/bash
      java -jar _EAP_HOME_/bin/.niogit/<SPACE>/<PROJECT_NAME>.git/hooks/git-push.jar
      注記

      To use post-commit Git hooks that execute Java code, you must use the following Java libraries:

      • JGit: Used to interact with internal Business Central Git repositories.
      • GitHub API for Java: Used to communicate with GitHub.

      For more information about post-commit Git hook and Java code examples, see Business Central post-commit Git Hooks Integration.