Jenkins groovy pipeline simple inheritance failure

I am trying to call a protected method of a parent class from a child class in a groovy script in the Jenkins pipeline. Jenkins crashes and says: " groovy.lang.MissingPropertyException: There is no such property: _parentValue for class: Child ".

However, if I run the same code in Intellij IDEA, it works fine. I have no idea why this does not work in Jenkins. Can anyone help?

The code:

public class Parent
{
    private int _parentValue

    public Parent()
    {
        _parentValue = 0
    }

    protected void Increment()
    {
        _parentValue = _parentValue + 1
    }
}

public class Child extends Parent
{
    public void IncrementFromChild()
    {
        // call parent method
        Increment()
    }
}

// Instantiate and call child method
def child = new Child()
child.IncrementFromChild()

Stacktrace:

groovy.lang.MissingPropertyException: No such property: _parentValue for  class: Child
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:53)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.getProperty(ScriptBytecodeAdapter.java:458)
at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.getProperty(DefaultInvoker.java:33)
at com.cloudbees.groovy.cps.impl.PropertyAccessBlock.rawGet(PropertyAccessBlock.java:20)
at Parent.Increment(WorkflowScript:12)
at Child.IncrementFromChild(WorkflowScript:20)
at WorkflowScript.run(WorkflowScript:25)
...
+4
source share
1 answer

, CPS- . . . Andrew Bayer .

, , , @NonCPS .

0

Source: https://habr.com/ru/post/1675378/


All Articles