Cannot create annotated git tag from groovy script

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?



Read more here: https://stackoverflow.com/questions/68473430/cannot-create-annotated-git-tag-from-groovy-script

Content Attribution

This content was originally published by u123 at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: