Reputation: 16287
Using:
Groovy Version: 3.0.8 JVM: 11.0.10 Vendor: Oracle Corporation OS: Linux
I have this script:
def shellCommand(String cmd) {
def process = cmd.execute()
def output = new StringWriter(), error = new StringWriter()
process.waitForProcessOutput(output, error)
println "exit value=${process.exitValue()}"
println "OUT: $output"
println "ERR: $error"
}
def gitRelease() {
def cmd001 = "git tag -a -m \"Release 0.0.777\" 0.0.45"
shellCommand(cmd001)
}
gitRelease()
When I run it from command line I get below error:
$ groovy myScript.groovy
exit value=128
OUT:
ERR: fatal: Failed to resolve '0.0.45' as a valid ref.
Same error if I try with slashy string:
def cmd001 = /git tag -a -m "Release 0.0.777" 0.0.45/
If I instead run git directly it works:
$ git tag -a -m "Release 0.0.777" 0.0.45
$ git tag
0.0.45
Creating a simple tag from the above groovy script works:
def gitRelease() {
//def cmd001 = "git tag -a -m \"Release 0.0.777\" 0.0.45"
def cmd001 = "git tag 0.0.46"
shellCommand(cmd001)
}
gives:
$ groovy myScript.groovy
exit value=0
OUT:
ERR:
Any suggestions?
Upvotes: 0
Views: 112
Reputation: 171084
The String.execute method often gives issues in unexpected places
There's another List.execute method that gives much more expected results
def cmd1 = ["git", "tag", "-a", "-m", "Release 0.0.777", "0.0.45"]
You should also change
def shellCommand(String cmd) {
To
def shellCommand(List cmd) {
Upvotes: 1