jenkinsci-unstashParam-library icon indicating copy to clipboard operation
jenkinsci-unstashParam-library copied to clipboard

for...in syntax is unsafe when presented with the CPS transform.

Open mikemol opened this issue 5 years ago • 1 comments

https://github.com/janvrany/jenkinsci-unstashParam-library/blob/dcd144e025a396fb9ee13d2e8fa6752aa246fb3c/vars/unstashParam.groovy#L9

It's not clearly documented, but that construct is unsafe. See https://jenkins.io/blog/2017/02/01/pipeline-scalability-best-practice/ , specifically:

@NonCPS functions can use a much broader subset of the Groovy language, such as iterators and functional features, which makes them more terse and fast to write.

And while working around that, pay attention to:

@NonCPS functions should not use Pipeline steps internally, however you can store the result of a Pipeline step to a variable and use it that as the input to a @NonCPS function.

Gotcha: It’s not guaranteed that use of a step will generate an error (there is an open RFE to implement that), but you should not rely on that behavior. You may see improper handling of exceptions, in particular.

It's annoying, but it's there.

mikemol avatar Jan 21 '20 15:01 mikemol

Yeah, I see. If you have a fix, I'd be happy to integrate it!

janvrany avatar Jan 21 '20 16:01 janvrany