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

Allow native as an alias for @NonCPS

XMLWordPrintable

      The @NonCPS annotation is hard to remember, and the meaning of the acronym is cryptic. The rule we want users to remember is something like: "there is Pipeline script code, which is limited in functionality, for example using non-Serializable local variables, but can run steps; and there is native code, which can do anything (subject to script security where applicable) but cannot run steps or other Pipeline script code". So perhaps it would be more intuitive to use the existing native method modifier:

      native String findSomeMetadata() {
        currentBuild.rawBuild.getAction(SomeJenkinsAPI).someGetter
      }
      sh "this is Pipeline script but it can call ${findSomeMetadata()}"
      

      Would need compiler patches, since by default the method attribute is left in and at runtime you get

      java.lang.ClassFormatError: Code attribute in native or abstract methods in class file WorkflowScript
      

            jglick Jesse Glick
            jglick Jesse Glick
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: