How can i generate a random string "0x8e84d87db2adaa58" using dsl plugin

15 views
Skip to first unread message

Ravi Teja

unread,
Nov 21, 2016, 6:16:24 AM11/21/16
to job-dsl-plugin
Hi,

Could some one help me out. To generate a random string starts with 0x or 0X "hexadecimal" as "0x8e84d87db2adaa58" using DSL plugin.

Thanks in Advance,
Ravi Tej

Victor Martinez

unread,
Nov 21, 2016, 2:36:18 PM11/21/16
to job-dsl-plugin
Hi,

you can do anything with Groovy, JobDSL is a Groovy DSL, so in your case you could use some snippet like:

def generator = { String alphabet, int n ->
  new Random().with {
    (1..n).collect { alphabet[ nextInt( alphabet.length() ) ] }.join()
  }
}

name='0x' + generator( (('A'..'F')+('0'..'9')).join(), 16 )

As an example, you can find further examples in the below stackoverflow thread (where I took the above snippet)

Cheers

Ravi Teja

unread,
Nov 22, 2016, 12:42:37 AM11/22/16
to job-dsl...@googlegroups.com
Thanks Victor Martinez, Its working fine

Thanks,
Ravi

--
You received this message because you are subscribed to a topic in the Google Groups "job-dsl-plugin" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/job-dsl-plugin/vs_adGTsgpQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to job-dsl-plugin+unsubscribe@googlegroups.com.
To post to this group, send email to job-dsl-plugin@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/job-dsl-plugin/47f44305-f51b-4107-aba5-98ea21d8fa98%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Thanks & Regards,
Ravi Teja
Reply all
Reply to author
Forward
0 new messages