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

Unable to use WorkflowScript multiple times in libraries class constructor

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • workflow-cps-plugin
    • None
    • Jenkins ver. 2.89.4
      Pipeline 2.5

      I build a Shared library using groovy classes that are located in the path /src.
      That classes use the WorkflowScript as constructor's argument, and that argument will be pass to the parent class, so it is possible to load all WorkflowScript properties like env and parms . When I try to instantiate multiple classes only the first class can access the WorkflowScript properties, if I change the order of instantiation then the first class can access the  WorkflowScript properties that in the previous order couldn't access

      In Example 1 the Foo class could access to the variables env, currentBuild and params , the class Foo and Stuff couldn't.

      In Example 2 I change the order and then the Bar class is the first class to be instantiated and now the Bar class could access the variables and the Foo couldn't.

      Could you help me to understand if it is a bug or miss use of the parent class

      Pipeline Example 1

       

      timestamps {
       node(env.NODE_NAME) {        
        def lib =   library("Common@${env.LIB_VERSION}").com.mycompany.jenkins             
        def fooLib = lib.Foo.new(this)        
        def barLib = lib.Bar.new(this)        
        def stuffLib = lib.Stuff.new(this)        
       }
      }

      Child Classes

       

      #Foo

       

      #/src/com/mycompany/jenkins/Foo.groovy
      package com.mycompany.jenkins
      
      class Foo extends WorkflowScriptLoader{
      
          Foo(script) {
              super(script)
          }
      }

       

      #Bar

       

      #/src/com/mycompany/jenkins/Bar.groovy
      package com.mycompany.jenkins 
      class Bar extends WorkflowScriptLoader{
        Bar(script) { 
          super(script) 
        }
      }
      

      #Stuff

       

       

      #/src/com/mycompany/jenkins/Stuff.groovy 
      package com.mycompany.jenkins 
      class Stuff extends WorkflowScriptLoader{ 
        Stuff(script) { 
          super(script) 
        } 
      }
      

      Parent Classe
      #WorkflowScriptLoader

       

       

      class WorkflowScriptLoader implements Serializable{
      
          def workFileScript
          def env
          def currentBuild
          def params
      
          WorkflowScriptLoader(script){
              workFileScript = script
              env = script.env
              currentBuild = script.currentBuild
              params = script.params
          }
      }

       

       

       

       

            Unassigned Unassigned
            moser_sts Stephane Moser
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: