第20章 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.
20.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
Create a
post-commitGit hook file:touch post-commit
$ touch post-commitCopy to Clipboard Copied! Toggle word wrap Toggle overflow Set the permissions of the
post-commitfile to755:chmod 755 post-commit
$ chmod 755 post-commitCopy to Clipboard Copied! Toggle word wrap Toggle overflow Add
#!/bin/bashand any required code to thepost-commitfile, for example:To push all changes to a remote repository:
#!/bin/bash git push origin +master
#!/bin/bash git push origin +masterCopy to Clipboard Copied! Toggle word wrap Toggle overflow To log a message:
#!/bin/bash echo 'Hello World'
#!/bin/bash echo 'Hello World'Copy to Clipboard Copied! Toggle word wrap Toggle overflow To execute code of another file:
#!/bin/bash java -jar _EAP_HOME_/bin/.niogit/<SPACE>/<PROJECT_NAME>.git/hooks/git-push.jar
#!/bin/bash java -jar _EAP_HOME_/bin/.niogit/<SPACE>/<PROJECT_NAME>.git/hooks/git-push.jarCopy to Clipboard Copied! Toggle word wrap Toggle overflow 注記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.