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

Whitelist more Functions for trivial operations on builtin types

XMLWordPrintable

      I have problems writing pipeline Scripts without having to approve several functions that are rather trivial operations of the most basic types. List of approvals follows, and some short fragments showing some code fragments using them.

      method java.lang.Object clone
      method java.util.Map putAll java.util.Map
      new java.util.AbstractMap$SimpleImmutableEntry java.lang.Object java.lang.Object
      new java.util.AbstractMap$SimpleEntry java.lang.Object java.lang.Object
      staticMethod org.codehaus.groovy.runtime.DefaultGroovyMethods minus java.lang.String java.lang.Object
      staticMethod org.codehaus.groovy.runtime.DefaultGroovyMethods plus java.util.Map java.util.Map
      
        // String minus operator
        def file = "foo.exe"
        def base = file - ".exe"
      

      Cloning a Map, so you can have a template and change fields without modifying the original.

           // we want to clone the map and change an entry without changing the original
          def browser = [:] + serverinfo.browser
          // or:
         def browser = [:].putAll(serverinfo.browser)
          // or:
          def browser = serverinfo.browser.clone()
          browser['repoUrl'] = browser['repoUrl'] + '/' + vcsurl
      
      // Convert a map to a list of Mapentries. Workaround for not beeing able to iterate those directly (the iterator is not serializable)
      @NonCPS
      def mapToList(depmap) {
          def dlist = []
          for (entry2 in depmap) {
              dlist.add(new java.util.AbstractMap.SimpleImmutableEntry(entry2.key, entry2.value))
          }
          dlist
      }
      // use it
      for (it2 in mapToList(mymap)) {
        echo "$it2.key = $it2.value (like the real thing!)"
      }
      

            jglick Jesse Glick
            nolange79 Norbert Lange
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: