2016-06-01 7 views
0

JenkinsでGroovyプラグインを使用していて、いくつかのGitリポジトリを操作したいと思います。JenkinsのGroovyシステムスクリプトからのGit操作

私はしたいと思います:

レポ A
  • 、チェックアウトはレポBX
  • をコミットし、チェックアウトはレポCY
  • をコミットし、コミットし

をプッシュしますGitプラグイン(Groovy内で)を使用してこれを行う方法を誰かに教えてもらえれば幸いです。特定のパスのシステムコマンド("git checkout X".execute(in_this_path)のようなものは素晴らしいでしょう。

答えて

0

課題は作業ディレクトリを変更することです。異なるパスで複数の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]) 
関連する問題