79824197

Date: 2025-11-19 08:22:46
Score: 2
Natty:
Report link

So I identified the problem when I write the code directly in a Jenkins script, the compilation environment is more tolerant and similar to a standard execution of groovy script. That’s why the annotations work.

However, when I use a Jenkins script from the SCM, it adopts a more restricted and optimized compilation process called CPS. This CPS compiler does not support all of Groovy’s features in the same way as standard script compilation. Thus, the CPS compiler considers @Field as an unrecognized annotation in the context of a dynamically loaded Jenkinsfile, causing compilation to fail.

The solution to use a persistent variable between different steps or methods from SCM is to use a shared library. You can view the documentation here: Jenkins Shared Libraries. https://www.jenkins.io/doc/book/pipeline/shared-libraries/ Since I don’t have the necessary rights in my Jenkins instance,

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • User mentioned (1): @Field
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: Sohaib El Mediouni