不工作:GitBlit groovy hook推送改变为其他Gitblit服务器repo

时间:2015-05-21 05:29:19

标签: git github groovy ssh gitblit

  

需要一个groovy push hook脚本,它将Gitblit实例的更改推送到另一个实例   Gitblit实例

我有两个私有linux servers,Say AB并且GitBlit安装在两者上。所有开发人员都会在服务器A上提交并推送他们的更改,我希望BA保持同步。

Assh://admin@serverA:29418/testrepo.git

最初我使用linux testrepoA从服务器B复制到scp command

Bssh://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();

我已使用Gitblit UI添加此脚本

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

服务器重启: 现在,当我要在serverA上推送文件时,为什么此脚本不会将更改推送到serverB

1 个答案:

答案 0 :(得分:2)

感谢james-moger

Cheers!! :)它正在使用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://admin@111.11.111.111:29418/testrepo.git").setPushAll().call();


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