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
.gitremote
configuration file -
Validation of the
.gitremote
configuration file for required parameters -
Patterns defined in the ignore parameter of the
.gitremote
file 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
$ git clone https://github.com/kiegroup/bc-git-integration-push.git
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Navigate to the cloned repository:
cd bc-git-integration-push
$ cd bc-git-integration-push
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Execute a Maven clean install:
mvn clean install
$ mvn clean install
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create a
/hooks
folder in yourEAP_HOME
directory:mkdir -p _EAP_HOME_/hooks/
$ mkdir -p _EAP_HOME_/hooks/
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Copy the
git-push-2.1-SNAPSHOT.jar
to theEAP_HOME/hooks/
folder:cp bc-git-integration-push/target/git-push-2.1-SNAPSHOT.jar _EAP_HOME_/hooks/
$ cp bc-git-integration-push/target/git-push-2.1-SNAPSHOT.jar _EAP_HOME_/hooks/
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: To create a template
.gitremote
configuration file, rungit-push-2.1-SNAPSHOT.jar
:java -jar git-push-2.1-SNAPSHOT.jar
$ java -jar git-push-2.1-SNAPSHOT.jar
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example template
.gitremote
configuration fileCopy to Clipboard Copied! Toggle word wrap Toggle overflow Modify the
.gitremote
configuration file parameters.Expand 表19.1 Example .gitremote parameters Parameter Description provider
The Git provider. Only two values are accepted: GIT_HUB and GIT_LAB. Required
login
The username for the Git provider. Required
password
A plain text password. Not required if a
token
is provided.token
A generated token to replace the
username
andpassword
based unsecured connection. Note: If this is not set a warning is displayed that you are using an unsecured connection. Not required if apassword
is provided. Note: GitLab only supports token authentication.remoteGitUrl
A 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.
useSSH
Boolean 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.ignore
A comma separated regular expressions to ignore project names that match any of these expressions. Optional.
githubOrg
Defines the repository organization if GitHub is used as the provider. Optional.
gitlabGroup
Defines the repository group and subgroup if GitLab is used as the provider Optional.
Create a
post-commit
Git hook file inEAP_HOME/hooks
:touch post-commit
$ touch post-commit
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Set the permissions of the
post-commit
file to755
:chmod 755 post-commit
$ chmod 755 post-commit
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Add
#!/bin/bash
and code to executegit-push-2.1-SNAPSHOT.jar
to thepost-commit
file:echo "#\!/bin/bash\njava -jar $APP_SERVER_HOME/hooks/git-push-2.1-SNAPSHOT.jar" > hooks/post-commit
$ echo "#\!/bin/bash\njava -jar $APP_SERVER_HOME/hooks/git-push-2.1-SNAPSHOT.jar" > hooks/post-commit
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Start Business Central with the
-Dorg.uberfire.nio.git.hooks
environment variable set. For example:./standalone.sh -c standalone-full.xml -Dorg.uberfire.nio.git.hooks=_EAP_HOME_/hooks
$ ./standalone.sh -c standalone-full.xml -Dorg.uberfire.nio.git.hooks=_EAP_HOME_/hooks
Copy 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.