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

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

    XMLWordPrintable

Details

    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

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

            quas Jakub Pawlinski added a comment - I would close it with "Valid workaround provided" but there is no such resolution available ;(
            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).

            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).
            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

            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
            abayer Andrew Bayer added a comment -

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

            abayer Andrew Bayer added a comment - kipras - you need to have import java.text.SimpleDateFormat at the top of your Pipeline.

            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.

            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

              Unassigned Unassigned
              owenmehegan Owen Mehegan
              Votes:
              12 Vote for this issue
              Watchers:
              22 Start watching this issue

              Dates

                Created:
                Updated: