Home > Software design >  How to sort Git tags in groovy?
How to sort Git tags in groovy?

Time:03-28

I am trying to fetch all git tags in descending order via groovy script. I am using below commands in my script.

def gettagsUrl = "git ls-remote --tags https://" bitbucketUser ":" bitbucketPass "bitbucket/scm/config/configurations-" "Object" ".git" "|" command

def command = ['#!/bin/bash', '-c' , sort -Vr -k2 ]

But I am getting below error:-

groovy.lang.MissingPropertyException: No such property: sort for class: Script1 at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:53)

My git version is 1.8.3.1

Can anyone help here. TIA

CodePudding user response:

The git tag command has an option to sort tags as version numbers :

git tag --sort="version:refname"

all the details can be read in the docs

CodePudding user response:

for this version Groovy scripts work for me for fetching tag

def gettagsUrl =[ "/bin/bash","-c" , "git ls-remote https://"   bitbucketUser   ":"   bitbucketPass
 "bitbucket/scm/config/configurations-"   "Object"  ".git" | awk '{print \$2}' | grep -v '\\^{}\$' | sort -r -V | sed 's@refs/tags/@@' " ]
  • Related