Best way to set a timestamp variable in Pipeline build

5,392 views
Skip to first unread message

Greg Smith

unread,
Jul 7, 2016, 3:51:43 PM7/7/16
to Jenkins Users

Hi,

I would like to set a timestamp at the beginning of my pipeline build, put it into the environment, and reuse it throughout my build. 

I found some sample code - but it no longer seems to work because of sandboxing of the groovy pipeline scripts.

The code is:
env.TIMESTAMP = new java.text.SimpleDateFormat('yyyyMMddHHmmss').format(new Date())

But I get this error now:
org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use new java.text.SimpleDateFormat java.lang.String
	at org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.StaticWhitelist.rejectNew(StaticWhitelist.java:185)

How should I be setting a timestamp value that I can reuse over throughout the rest of my build?

Thanks,
Greg


Baptiste Mathus

unread,
Jul 8, 2016, 11:20:27 AM7/8/16
to jenkins...@googlegroups.com

Probably you simply want to allow that finding call.
Open the /scriptApproval screen for that purpose.

Depending on what you're trying to do. Maybe using long start = System.currentTimeMillis() would suit your needs and be already whitelisted (can't check just now).

HTH

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/fae69470-a517-4167-a9fb-655170f92084%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Greg Smith

unread,
Jul 11, 2016, 9:52:01 AM7/11/16
to Jenkins Users, m...@batmat.net

Thanks,

That was my fix -- I went to that screen under Manage Jenkins and set those calls to be allowed in the sandbox. 

Thanks for the help.

Cheers,
Greg
Reply all
Reply to author
Forward
0 new messages