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

Getting MissingPropertyException when using binding in groovy scripts

    XMLWordPrintable

Details

    Description

       We have a task to read the particular string from current job console output and send in mail.

      I tried the below code to achieve this. This is written in Pipeline flow jenkinsfile from git.

      import java.*
      import java.lang.*
      import hudson.*
      import hudson.model.*
      import jenkins.model.Jenkins

      node() {

      def binding = getBinding()
      def manager = binding.getVariable("manager")
      def log = manager.build.logFile.text
      echo "${log}"
      }

      Always getting the below error.

      groovy.lang.MissingPropertyException: No such property: manager for class: groovy.lang.Binding at groovy.lang.Binding.getVariable(Binding.java:63)
      at groovy.lang.Binding$getVariable.call(Unknown Source)
      at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
       
       Detailed error are attached.

      Jenkins version 2.19.1

      Attachments

        Activity

          jglick Jesse Glick added a comment -

          manager is predefined, not in the bindings, IIRC. Check plugin documentation.

          jglick Jesse Glick added a comment - manager is predefined, not in the bindings, IIRC. Check plugin documentation.
          jayaram_s jayaram s added a comment -

          Hi Jesse,

           

          If I use as below also I am getting error

           

          def list = manager.build.logFile.readLines()
          echo "Log $list"

          groovy.lang.MissingPropertyException: No such property: manager for class: groovy.lang.Binding

           

          Regards

          Jayaram

          jayaram_s jayaram s added a comment - Hi Jesse,   If I use as below also I am getting error   def list = manager.build.logFile.readLines() echo "Log $list" groovy.lang.MissingPropertyException: No such property: manager for class: groovy.lang.Binding   Regards Jayaram
          jayaram_s jayaram s added a comment -

          Is there any plugin required to use manager object?

          jayaram_s jayaram s added a comment - Is there any plugin required to use manager object?
          jglick Jesse Glick added a comment -

          Yes, the Groovy Postbuild plugin.

          jglick Jesse Glick added a comment - Yes, the Groovy Postbuild plugin.

          People

            wolfs Stefan Wolf
            jayaram_s jayaram s
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: