All references to potentially non-Serializable objects, including most Jenkins API model objects, must be encapsulated in a method marked @NonCPS. Since such idioms will be rejected by sandboxed scripts, the norm in secured instances, it is generally advisable to create a safe façade in a global library. For this kind of access normally you would want to use the return value of a build step, which provides sandbox-safe information, though currently it does not provide special support for matrix projects (would be a separate RFE). |