0

需要一个 groovy 推送挂钩脚本,将更改从您的 Gitblit 实例推送到另一个 Gitblit 实例

我有两个 private linux servers, SayABwith GitBlitinstall 。所有开发人员都在服务器上提交并推送他们的更改A,我希望BA.

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

最初我已经testrepo从服务器复制AB使用 linuxscp 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

4

1 回答 1

2

谢詹姆斯莫格

Cheers!! :)它与推钩一起使用

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*******************")
于 2015-06-15T04:53:02.500 回答