无法从 groovy 脚本创建带注释的 git 标签
Cannot create annotated git tag from groovy script
使用:
Groovy Version: 3.0.8 JVM: 11.0.10 Vendor: Oracle Corporation OS: Linux
我有这个脚本:
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()
当我从命令行 运行 时,出现以下错误:
$ groovy myScript.groovy
exit value=128
OUT:
ERR: fatal: Failed to resolve '0.0.45' as a valid ref.
如果我使用 slashy 字符串尝试同样的错误:
def cmd001 = /git tag -a -m "Release 0.0.777" 0.0.45/
如果我直接 运行 git 就可以了:
$ git tag -a -m "Release 0.0.777" 0.0.45
$ git tag
0.0.45
从上面的 groovy 脚本创建一个简单的标签有效:
def gitRelease() {
//def cmd001 = "git tag -a -m \"Release 0.0.777\" 0.0.45"
def cmd001 = "git tag 0.0.46"
shellCommand(cmd001)
}
给出:
$ groovy myScript.groovy
exit value=0
OUT:
ERR:
有什么建议吗?
String.execute 方法经常在意想不到的地方出现问题
还有另一种 List.execute 方法可以提供更多预期结果
def cmd1 = ["git", "tag", "-a", "-m", "Release 0.0.777", "0.0.45"]
你也应该改变
def shellCommand(String cmd) {
到
def shellCommand(List cmd) {
使用:
Groovy Version: 3.0.8 JVM: 11.0.10 Vendor: Oracle Corporation OS: Linux
我有这个脚本:
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()
当我从命令行 运行 时,出现以下错误:
$ groovy myScript.groovy
exit value=128
OUT:
ERR: fatal: Failed to resolve '0.0.45' as a valid ref.
如果我使用 slashy 字符串尝试同样的错误:
def cmd001 = /git tag -a -m "Release 0.0.777" 0.0.45/
如果我直接 运行 git 就可以了:
$ git tag -a -m "Release 0.0.777" 0.0.45
$ git tag
0.0.45
从上面的 groovy 脚本创建一个简单的标签有效:
def gitRelease() {
//def cmd001 = "git tag -a -m \"Release 0.0.777\" 0.0.45"
def cmd001 = "git tag 0.0.46"
shellCommand(cmd001)
}
给出:
$ groovy myScript.groovy
exit value=0
OUT:
ERR:
有什么建议吗?
String.execute 方法经常在意想不到的地方出现问题
还有另一种 List.execute 方法可以提供更多预期结果
def cmd1 = ["git", "tag", "-a", "-m", "Release 0.0.777", "0.0.45"]
你也应该改变
def shellCommand(String cmd) {
到
def shellCommand(List cmd) {