課題は作業ディレクトリを変更することです。異なるパスで複数のgitリポジトリを操作できます。これを解決するために、ディレクトリ(File directory)メソッドを持つjava.lang.ProcessBuilderを使用して、作業ディレクトリを変更します。 は完全な例です:
//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])