In my declarative Jenkins pipeline I have added code which should approve scripts as suggested here:
... } catch (Exception jobFailed) { if (jobFailed.getMessage() == "script not yet approved for use") { echo("[WARNING] Changes in delivery job were automatically approved") approveDeliveryJob() return false } ... @NonCPS def approveDeliveryJob() { toApprove = ScriptApproval.get().getPendingScripts().collect() toApprove.each { pending -> ScriptApproval.get().approveScript(pending.getHash())} } } ... As suggested here
to solve this put all the code that works with non serializable variables into
@NonCPSannotated function
What I am missing?