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

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
            Votes:
            3 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: