2017-10-17 51 views
1

我想獲取有關特定提交的信息。如何將管道添加到命令行?如何將管道添加到groovy exec命令行?

def getCommitLog(commit){ 
    def stdout = new ByteArrayOutputStream() 
    exec { 
     ignoreExitValue true 
     workingDir 'my_dir' 
     commandLine 'git', 'log', '--decorate', '|', 'grep', commit 
     standardOutput = stdout 
    } 
    def retval = stdout.toString().trim() 
    return retval 

它拋出這個錯誤:

fatal: ambiguous argument '|': unknown revision or path not in the working tree. 
Use '--' to separate paths from revisions, like this: 
'git <command> [<revision>...] -- [<file>...] 
+0

你可以顯示'exec'方法的樣子嗎? –

回答

0

可能是你可以嘗試改變如下,即,使用列表

來自:

commandLine 'git', 'log', '--decorate', '|', 'grep', commit 

到:

commandLine ['git', 'log', '--decorate', '|', 'grep', 'commit'] 
+0

無法強制將類java.lang.String的對象git強制轉換爲類'int' –

+0

是的,我將此用於具有上述錯誤的行我發佈: commandLine ['git','log','--decorate', '|','grep',提交] –