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

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

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Fixed
    • Component/s: groovy-plugin
    • Labels:
      None
    • Environment:
      centos7
      Jenkins ver. 2.60.1
      Pipeline groovy 2.36.1
      Pipeline: Shared Groovy Libraries 2.8
    • Similar Issues:

      Description

      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.

        Attachments

          Issue Links

            Activity

            Hide
            john_fo John Forrest added a comment -

            This appears to have been fixed in latest version. Guessing by fix for JENKINS-34599, although it is not quite the same issue.

            Show
            john_fo John Forrest added a comment - This appears to have been fixed in latest version. Guessing by fix for  JENKINS-34599 , although it is not quite the same issue.
            Hide
            john_fo John Forrest added a comment -

            Can confirm this is now fixed, so closing.

            Show
            john_fo John Forrest added a comment - Can confirm this is now fixed, so closing.

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved: