需要一个groovy push hook脚本,它将Gitblit实例的更改推送到另一个实例 Gitblit实例
我有两个私有linux servers
,Say A
和B
并且GitBlit
安装在两者上。所有开发人员都会在服务器A
上提交并推送他们的更改,我希望B
与A
保持同步。
A
:ssh://admin@serverA:29418/testrepo.git
最初我使用linux testrepo
将A
从服务器B
复制到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();
我已使用Gitblit UI添加此脚本
testresopistory.git> edit> receive> post-receive scripts> selected(pushserver)
服务器重启:
现在,当我要在serverA
上推送文件时,为什么此脚本不会将更改推送到serverB
?
答案 0 :(得分:2)
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*******************")