Expected Behavior
The tested script correctly handles fields annotated @field in all methods
Actual Behavior
Methods access the wrong instance of the field
Steps to Reproduce
define script :
vars/testFiled.groovy
import groovy.transform.Field
@Field f = "test"
def call(Map _args) {
node {
stage("set f") {
echo(f)
f = "test2"
setF()
}
}
}
def setF() {
// field f should contains value "test2" but contains "test" instead
echo (f)
}
define test:
import com.homeaway.devtools.jenkins.testing.JenkinsPipelineSpecification
class TestFieldSpec extends JenkinsPipelineSpecification {
def "should echo test test2"() {
given:
def testField = loadPipelineScriptForTest("vars/testField.groovy")
when:
testField()
then:
1 * getPipelineMock("echo")('test')
1 * getPipelineMock("echo")('test2')
}
}
Test fails:
Too many invocations for:
1 * getPipelineMock("echo")('test') (2 invocations)
Additional Information
Tested with Java 1.8 and 11 and jenkins-spock.version 2.1.5
Script works as expected in Jenkins
Expected Behavior
The tested script correctly handles fields annotated @field in all methods
Actual Behavior
Methods access the wrong instance of the field
Steps to Reproduce
define script :
vars/testFiled.groovy
define test:
Test fails:
Too many invocations for:
1 * getPipelineMock("echo")('test') (2 invocations)
Additional Information
Tested with Java 1.8 and 11 and jenkins-spock.version 2.1.5
Script works as expected in Jenkins