Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the script name in Groovy

How do I get the name of the script being executed in Groovy?

It is not a command line argument and hence the args array is not of any help.

like image 637
itsraghz Avatar asked Mar 24 '16 11:03

itsraghz


Video Answer


1 Answers

You can get the present script name as follows.

def scriptName = this.class.getName()
println "Script FQCN : " + scriptName

It will print out the name of the script (which is nothing but a Class) with its package name - FQCN (Fully Qualified Class Name).

If you want just the script name and NOT the package, you can use

println "Script Simple Name : " + this.class.getSimpleName()
like image 100
itsraghz Avatar answered Oct 27 '22 21:10

itsraghz