19.5. Integrating remote Git repositories
In the following example, you use a post-commit Git hook and Java code to integrate Business Central with a remote Git repository. For the Java code example, see Business Central post-commit Git Hooks Integration. The example provides the following functionality:
-
Automatic generation of the template
.gitremoteconfiguration file -
Validation of the
.gitremoteconfiguration file for required parameters -
Patterns defined in the ignore parameter of the
.gitremotefile are ignored by Git - Message and notification output to users
- Support for GitLab and GitHub token authentication
- Support for GitLab group and subgroup project creation
- Support for GitHub organization repository creation
Prerequisites
- Red Hat Decision Manager is installed in a Red Hat JBoss EAP 7.2 server instance.
- Java Development Kit (JDK) 8 is installed.
- Maven is installed.
Procedure
In a terminal window, clone the GitHub repository to your system:
$ git clone https://github.com/kiegroup/bc-git-integration-push.git
Navigate to the cloned repository:
$ cd bc-git-integration-push
Execute a Maven clean install:
$ mvn clean install
Create a
/hooksfolder in yourEAP_HOMEdirectory:$ mkdir -p _EAP_HOME_/hooks/
Copy the
git-push-2.1-SNAPSHOT.jarto theEAP_HOME/hooks/folder:$ cp bc-git-integration-push/target/git-push-2.1-SNAPSHOT.jar _EAP_HOME_/hooks/
Optional: To create a template
.gitremoteconfiguration file, rungit-push-2.1-SNAPSHOT.jar:$ java -jar git-push-2.1-SNAPSHOT.jar
Example template
.gitremoteconfiguration file#This is an auto generated template empty property file provider=GIT_HUB login= password= token= remoteGitUrl=https://api.github.com/ useSSH=false ignore=.*demo.*, test.* githubOrg=OrgName gitlabGroup=Group/subgroup
Modify the
.gitremoteconfiguration file parameters.表19.1 Example
.gitremoteparametersParameter Description providerThe Git provider. Only two values are accepted: GIT_HUB and GIT_LAB. Required
loginThe username for the Git provider. Required
passwordA plain text password. Not required if a
tokenis provided.tokenA generated token to replace the
usernameandpasswordbased unsecured connection. Note: If this is not set a warning is displayed that you are using an unsecured connection. Not required if apasswordis provided. Note: GitLab only supports token authentication.remoteGitUrlA public provider URL or a locally hosted enterprise for any provider. Required. Note: The public GitHub URL should be the API URL. For example, api.github.com.
useSSHBoolean to allow the SSH protocol to push changes to the remote repository. Optional. Default = false. Note: This parameter uses the local
~/.ssh/directory to obtain the SSH configuration.ignoreA comma separated regular expressions to ignore project names that match any of these expressions. Optional.
githubOrgDefines the repository organization if GitHub is used as the provider. Optional.
gitlabGroupDefines the repository group and subgroup if GitLab is used as the provider Optional.
Create a
post-commitGit hook file inEAP_HOME/hooks:$ touch post-commit
Set the permissions of the
post-commitfile to755:$ chmod 755 post-commit
Add
#!/bin/bashand code to executegit-push-2.1-SNAPSHOT.jarto thepost-commitfile:$ echo "#\!/bin/bash\njava -jar $APP_SERVER_HOME/hooks/git-push-2.1-SNAPSHOT.jar" > hooks/post-commit
Start Business Central with the
-Dorg.uberfire.nio.git.hooksenvironment variable set. For example:$ ./standalone.sh -c standalone-full.xml -Dorg.uberfire.nio.git.hooks=_EAP_HOME_/hooks
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.