Shared library Enum fails on valueOf

This issue is archived. You can view it, but you can't modify it. Learn more

XMLWordPrintable

      Hi, I'm trying to use this dead simple enum in a shared library:

      package x.y.z
      enum ProjectTypes {
          python,
          node
          // workaround https://issues.jenkins.io/browse/JENKINS-33023
          ProjectTypes() {}
      }

      but I'm hitting a ridiculous bunch of errors. This time I'm really desperate and didn't find any workaround.
      The enum is placed in the library's /src directory and called from a method in a /vars script, that does type coercion from a string such as this, let's call it tripMine.groovy:

      import x.y.z.ProjectTypes
      def call(String projectTypeStr) {
          return projectTypeStr as ProjectTypes
      }

      This is supposed to work thanks to enum's valueOf() static method, but if I call it from a basic scripted pipeline (where the library is included on the folder-level):

      @Library('my-library@my-branch') _
      node {
          stage('trip') {
              def trouble = tripMine('python')
          }
      } 

      I get this exception back:

      org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: No such static method found: staticMethod x.y.z.ProjectTypes valueOf java.lang.Class java.lang.String 

      This is the main trouble, but the fun continues.

      The exception is from the script-security-plugin, I'm an admin, so I can easily whitelist that in the In-process script approval page, but yikes, it's not there. I found JENKINS-53700, but that's why I abandoned the usual declarative pipeline and used the scripted one. Still no dice.

      Next I tried to add the method to the enum:

      static ProjectTypes valueOf(Class clazz, String str) {
          return python
      } 

      This time the execution passed (why?), but reimplementing the whole method defies the very reason I used enum in the first place.

       

      Is there something sensible I can do to make this work? I've also found this "improvement" suggestion JENKINS-56948, which looks quite like the same thing, but I don't believe that's an improvement material. Hope I'm right   Thanks a lot!

            Assignee:
            Unassigned
            Reporter:
            Vit
            Archiver:
            Jenkins Service Account

              Created:
              Updated:
              Archived: