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

pipeline scripts don't like final properties being set in the constructor

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • groovy-plugin
    • None
    • centos7
      Jenkins ver. 2.60.1
      Pipeline groovy 2.36.1
      Pipeline: Shared Groovy Libraries 2.8

      I'm seeing this at least when I load scripts from another - I refer to these as subscripts. My usual pattern is to wrap all the code in there into a class, such as:

      class FooSubScript{

          final def steps

          FooSubScript(steps) {
              this.steps = steps
          }
      ....

      I've only recently started doing this, to better share code between several scripts. The pattern has been working over the last few weeks but suddenly stopped working, I believe yesterday. I get errors along the lines of:

      groovy.lang.ReadOnlyPropertyException: Cannot set readonly property: globals for class: setupSubScript
      at groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:2744)
      at groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:3770)
      at setupSubScript.setProperty(Script1.groovy)

      (in this particular example, the first property was called globals)

      As far as I can see that is perfectly valid groovy. Commenting or deleting the final makes it work.

            vjuranek vjuranek
            john_fo John Forrest
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: