Not working: GitBlit groovy hook which push changed to other Gitblit server repo

820 Views Asked by At

Need a groovy push hook scripts which push changes from your Gitblit instance to another Gitblit instance

I have two private linux servers, Say A and B with GitBlit install on both. All developers do commit and push their changes on server A, I want B keep in sync with A.

A : ssh://admin@serverA:29418/testrepo.git

Initially I have copied testrepo from server A to B using linux scp command

B : ssh://admin@serverB:29418/testrepo.git

pushserver.groovy :

import com.gitblit.GitBlit
import com.gitblit.Keys
import com.gitblit.models.RepositoryModel
import com.gitblit.models.TeamModel
import com.gitblit.models.UserModel
import com.gitblit.utils.JGitUtils
import com.gitblit.utils.StringUtils
import java.text.SimpleDateFormat
import org.eclipse.jgit.api.CloneCommand
import org.eclipse.jgit.api.Git
import org.eclipse.jgit.lib.Repository
import org.eclipse.jgit.lib.Config
import org.eclipse.jgit.revwalk.RevCommit
import org.eclipse.jgit.transport.ReceiveCommand
import org.eclipse.jgit.transport.ReceiveCommand.Result
import org.eclipse.jgit.util.FileUtils
import org.slf4j.Logger

File baseFolder = GitBlit.getFileOrFolder(Keys.git.repositoriesFolder)
File repoFolder = new File(baseFolder, repository.name);
Git git = Git.open(repoFolder, FS.detect())
git.push().setRemote("ssh://admin@serverB:29418/testrepo.git").setPushAll().call();

I have added this script using Gitblit UI

testresopistory.git> edit> receive> post-receive scripts> selected(pushserver)

Server restarted : Now when I am going to push a file on serverA then why this script not push changes to serverB ?

1

There are 1 best solutions below

0
On BEST ANSWER

Thanks to james-moger

Cheers!! :) It's working with pushhook

import com.gitblit.GitBlit
import com.gitblit.Keys
import com.gitblit.models.RepositoryModel
import com.gitblit.models.TeamModel
import com.gitblit.models.UserModel
import com.gitblit.utils.JGitUtils
import com.gitblit.utils.StringUtils
import java.text.SimpleDateFormat
import org.eclipse.jgit.api.CloneCommand
import org.eclipse.jgit.api.Git
import org.eclipse.jgit.lib.Repository
import org.eclipse.jgit.lib.Config
import org.eclipse.jgit.revwalk.RevCommit
import org.eclipse.jgit.transport.ReceiveCommand
import org.eclipse.jgit.transport.ReceiveCommand.Result
import org.eclipse.jgit.util.FileUtils
import org.eclipse.jgit.util.FS
import org.slf4j.Logger


logger.info("*************** START CUSTOM PUSH *******************")

File baseFolder = new File("/root/softwares/apache-tomcat-6.0.32/webapps/gitblit/WEB-INF/data/git");
File repoFolder = new File(baseFolder, repository.name);
Git git = Git.open(repoFolder, FS.detect())
git.push().setRemote("ssh://[email protected]:29418/testrepo.git").setPushAll().call();


logger.info("*************** DONE CUSTOM PUSH*******************")