Search code examples
seleniumselenium-webdriverjgitjgitflow-maven-plugin

Need Example of JGit to push code files to git server


I am trying to push the selenium scripts to git server so that jenkins will automatically download the latest scripts. I wanted to give web interface to select the automation scripts and upload the same scripts in Git. I want to programatically handle the pushing of choosen files to server so that only those files are run for automation. I need an example from JGit.


Solution

  • You use the PushCommand for invoking a push to a remote server. There are options among others for choosing which remote is pushed to.

    Keep in mind that you cannot push some files selectively, but only whole commits on a branch, so there is no way to do what you would like with simple push. An option would be to create separate commits on a separate branch and only push this one branch via defining the references via the PushCommand.add() method.

    try (Git git = new Git(repository)) {
        git.push().call();
    }
    

    See also a related snippet in the jgit-cookbook