如何使用 grgit API 获取 git 远程 url

问题描述

我需要使用 grgit API 在我的 groovy 脚本中读取 git 远程 url 以下的 .git 文件夹。

url = git@github.com:***/****.git

你能帮忙吗

解决方法

我可以做如下

import org.ajoberstar.grgit.Grgit

Grgit git = new Grgit()
def gitRoot = project.hasProperty('git.root') ? project.property('git.root') : project.rootProject.projectDir
git = Grgit.open(dir: gitRoot)
System.out.println("git.remote.list().url -->"+git.remote.list().url)