Documentation should clarify distinction between global variable access vs. plain class references

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

XMLWordPrintable

      Documentation says "Internally, scripts in the vars directory are instantiated as a singleton on-demand, when used first."

      Here is a very basic example to demonstrate it's not the case:

      // vars/acme.groovy
      
      def setFoo(v) {
          this.foo = v;
      }
      def getFoo() {
          return this.foo;
      }
      
      // src/com/foo/Zot.groovy
      
      package com.foo
      
      def printAcmeFoo() {
          try {
              echo acme.foo
          } catch (e){
              echo "acme.foo is undefined"
          }
      }
      

      And here is a pipeline:

      import com.foo.Zot
      
      node{
          acme.foo = "5"
          echo acme.foo;
          
          Zot z = new Zot()    
          z.printAcmeFoo()
      }
      

      Actually it shows 2 issues:
      1/ scripts in the vars directory are not singletons
      2/ when accessing undefined field pipeline will hang indefinitely

            Assignee:
            Jesse Glick
            Reporter:
            Martin Vehovsky
            Archiver:
            Jenkins Service Account

              Created:
              Updated:
              Resolved:
              Archived: