'How to add pipe to groovy exec command-line?
I am trying to get information on a specific commit. How do I add a pipe to the command-line?
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
It throws this error:
fatal: ambiguous argument '|': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]
Solution 1:[1]
Use a subshell: ['bash', '-c', '<entire command>']
exec {
commandLine = ['bash', '-c', 'find build/ -iname log4j.xml | xargs ls -lh' ]
}
Solution 2:[2]
May be you can try changing as below i.e., use list
from:
commandLine 'git', 'log', '--decorate', '|', 'grep', commit
to:
commandLine ['git', 'log', '--decorate', '|', 'grep', 'commit']
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Sridhar Sarnobat |
| Solution 2 |
