Die Herausforderung besteht darin, das Arbeitsverzeichnis zu ändern, also können Sie an mehreren Git-Repositories in verschiedenen Pfaden arbeiten. Um es zu lösen, benutze ich java.lang.ProcessBuilder, das Verzeichnis (Dateiverzeichnis) -Methode hat, das das Arbeitsverzeichnis ändert. Hier ist ein vollständiges Beispiel:
//executes the command in the working dir
//and prints the output to a log file
def runProcess(workingDir, command) {
ProcessBuilder procBuilder = new ProcessBuilder(command);
procBuilder.directory(workingDir);
procBuilder.redirectOutput(new File("${workingDir}/groovyGit.log"))
Process proc = procBuilder.start();
def exitVal = proc.waitFor()
println "Exit value: ${exitVal}"
return proc
}
//configuring the working dir for each git repository
def repoA = "repo A working dir"
def repoB = "repo B working dir"
def repoC = "repo C working dir"
//configuring the wanted revision to checkout for each repository
def repoARevision = "repo a revision"
def repoBRevision = "repo b revision"
def commitMsg = "commit msg"
//checkout A
runProcess(new File(repoA), ["git", "checkout", repoARevision])
//checkout B
runProcess(new File(repoB), ["git", "checkout", repoBRevision])
//check status before commit
runProcess(new File(repoC), ["git", "status"])
//commit
runProcess(new File(repoC), ["git", "commit", "-a", "-m", commitMsg])