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

Setters for shared pipeline scripts not getting called

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • workflow-cps-plugin
    • None
    • Jenkins LTS 2.46.3
      Pipeline v2.5

      According to the Jenkins docs, one should be able to define getters and setters for global variables in shared pipeline scripts to manipulating fields. This does not seem to work correctly. Take the following example which is a slight variation on the example from the docs:

       

      // tmp_shared/vars/acme.groovy
      def setName(value) {
          echo "Setting name to $value"
          this.@name = value
      }
      def getName() {
          echo "Getting name of " + this.@name
          return this.@name
      }
      
      // Pipeline script
      @Library ('tmp_shared') _
      
      acme.name = 'Alice'  // should print "Setting name to Alice" to the console
      def tmp = acme.name  // should print "Getting name of Alice" to the console

      I'd expect the output from this simple test to look something like this:

      ...
      Setting name to Alice
      Getting name of Alice
      ...

      However I see no console output whatsoever. This indicates that the getter and setter methods are not being invoked at all when defined in the Groovy vars scripts for a shared pipeline library. 

       

            Unassigned Unassigned
            leedega Kevin Phillips
            Votes:
            2 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated: