jenkins-spock icon indicating copy to clipboard operation
jenkins-spock copied to clipboard

groovy code has different behavior between Jenkins and test execution

Open Ginxo opened this issue 5 years ago • 3 comments

Expected Behavior

I have a groovy piece of code (and it's not the only case) where the behavior is different for test and Jenkins execution I have all Jenkins instance plugins added as dependency in my project but I can reproduce it in tests.

The code is

['a', 'b'].each { it -> println(it) }

The jenkins output is

WorkflowScript: 56: The current scope already contains a variable of the name it
 @ line 56, column 78.
   ['a', 'b'].each { it -> pr

I know I can replace code by ['a', 'b'].each { println(it) } but make me wonder how accurate the tests are.

Actual Behavior

The code is working in tests but in Jenkins

Ginxo avatar Jul 01 '20 08:07 Ginxo

I believe that Jenkins is actually wrong here. Jenkins has had trouble for a while with supporting Groovy-style iterative blocks in Jenkins' CPS-transformed pipeline script engine.

Jenkins-Spock does not apply the CPS transformation that Jenkins does, so there are some idiosyncrasies that Jenkins might exhibit that will not show up in Jenkins-Spock.

You should think of Jenkins-Spock as a way to unit-test your Jenkins Pipeline code for correct input/output, not as a way to test a Jenkins Pipeline's runtime behavior. There are other tools (like jenkinsfilerunner) if you want to "actually" run a pipeline in Jenkins as a "test."

Which version of Jenkins are you using? Which version of the workflow-cps-plugin is installed on your Jenkins master?

I cannot reproduce this issue with the current version of jenkins-spock in the master branch. I cannot reproduce this issue with Jenkins 2.204.2.2 and workflow-cps-plugin version 2.79 (which uses groovy-cps version 1.3.2, which uses Groovy version 2.4.7)

Is your Jenkins environment up-to-date?

awittha avatar Jul 21 '20 18:07 awittha

@awittha thanks a lot for the explanation.

  • Jenkins 2.150.2 https://github.com/kiegroup/jenkins-pipeline-shared-libraries/blob/10b6fa5531ee39e23ff453df878bb4eb9f81e29c/pom.xml#L25
  • workflow-cps-plugin 2.72 https://github.com/kiegroup/jenkins-pipeline-shared-libraries/blob/10b6fa5531ee39e23ff453df878bb4eb9f81e29c/pom.xml#L27

Ginxo avatar Jul 22 '20 05:07 Ginxo

Ah, those are the versions in your jenkins-spock dependencies - is that the same version of Jenkins and the same version of workflow-cps that are actually running when you run the code in Jenkins for real?

awittha avatar Jul 22 '20 14:07 awittha