manish soni
manish soni

Reputation: 575

How to sort Git tags in groovy?

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

Upvotes: 1

Views: 696

Answers (2)

Parth Shah
Parth Shah

Reputation: 874

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/@@' " ]

Upvotes: 1

LeGEC
LeGEC

Reputation: 51810

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

Upvotes: 1

Related Questions