Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-27725

Unclassified error on Date.parse(String, String) from DefaultGroovyStaticMethods

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      If I create a workflow script and run it in the Groovy Sandbox, with this line:
      now = new Date().format("yyyyMMdd")

      I get this error:
      org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: unclassified method java.util.Date format java.lang.String

      And I do not get any option to approve it for use in the Script Approval UI. If I don't use the sandbox, the script works OK.

        Attachments

          Issue Links

            Activity

            Hide
            quas Jakub Pawlinski added a comment -

            I would close it with "Valid workaround provided" but there is no such resolution available ;(

            Show
            quas Jakub Pawlinski added a comment - I would close it with "Valid workaround provided" but there is no such resolution available ;(
            Hide
            jglick Jesse Glick added a comment -

            Existence of a workaround does not mean a bug should be closed! It should be fixed. So far I have not had time to work on it, but that may change, or someone else might offer a fix (with test).

            Show
            jglick Jesse Glick added a comment - Existence of a workaround does not mean a bug should be closed! It should be fixed. So far I have not had time to work on it, but that may change, or someone else might offer a fix (with test).
            Hide
            kipras Kipras Mancevicius added a comment - - edited
            org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
            WorkflowScript: 98: unable to resolve class SimpleDateFormat 

            when trying to use new SimpleDateFormat('yyyyMMdd.HHmmss').parse()

            Is there some other way to parse dates? As noted above Date.parse() does not work either.

            Jenkins version: 2.60.2
            Pipeline plugin version: 2.5
            Pipeline Groovy plugin version: 2.39

            Show
            kipras Kipras Mancevicius added a comment - - edited org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: WorkflowScript: 98: unable to resolve class SimpleDateFormat when trying to use  new SimpleDateFormat('yyyyMMdd.HHmmss').parse() Is there some other way to parse dates? As noted above Date.parse() does not work either. Jenkins version: 2.60.2 Pipeline plugin version: 2.5 Pipeline Groovy plugin version: 2.39
            Hide
            abayer Andrew Bayer added a comment -

            Kipras Mancevicius - you need to have import java.text.SimpleDateFormat at the top of your Pipeline.

            Show
            abayer Andrew Bayer added a comment - Kipras Mancevicius - you need to have import java.text.SimpleDateFormat at the top of your Pipeline.
            Hide
            mb_o Moritz Baumann added a comment -

            An idiomatic way to get the current day of the week in Groovy would be:

            new Date()[Calendar.DAY_OF_WEEK]
            

            This also fails with the following error message:

            Scripts not permitted to use staticMethod org.codehaus.groovy.runtime.DateGroovyMethods getAt java.util.Date int
            

            Just wanted to make sure this particular method as well, since nobody else mentioned it before and IMO that should be allowed as well.

            Show
            mb_o Moritz Baumann added a comment - An idiomatic way to get the current day of the week in Groovy would be: new Date()[Calendar.DAY_OF_WEEK] This also fails with the following error message: Scripts not permitted to use staticMethod org.codehaus.groovy.runtime.DateGroovyMethods getAt java.util.Date int Just wanted to make sure this particular method as well, since nobody else mentioned it before and IMO that should be allowed as well.

              People

              • Assignee:
                Unassigned
                Reporter:
                owenmehegan Owen Mehegan
              • Votes:
                9 Vote for this issue
                Watchers:
                21 Start watching this issue

                Dates

                • Created:
                  Updated: