Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

groovy code has different behavior between Jenkins and test execution #79

Open
Ginxo opened this issue Jul 1, 2020 · 3 comments
Open

Comments

@Ginxo
Copy link

Ginxo commented Jul 1, 2020

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

@awittha
Copy link
Contributor

awittha commented Jul 21, 2020

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
Copy link
Contributor

awittha commented Jul 22, 2020

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants