How to sort git tags in groovy?

by raphael_tillman , in category: Third Party Scripts , 4 months ago

How to sort git tags in groovy?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by ryleigh , 4 months ago

@raphael_tillman 

You can sort Git tags in Groovy by using the following code snippet:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
def tags = []
def process = 'git tag'.execute()
process.in.eachLine { line ->
    tags.add(line)
}
process.waitFor()

tags.sort()

tags.each { tag ->
    println tag
}


This code snippet will execute the git tag command to fetch all the tags in the repository. It will then store the tags in a list and sort them using the sort() method. Finally, it will iterate over the sorted tags and print them out.