2

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 @NonCPS annotated function

What I am missing?

1 Answer 1

4
toApprove = ScriptApproval.get().getPendingScripts().collect() 

Here you are storing the result in the script binding, which is affected by serialization.

You need a local variable instead:

 def toApprove = ScriptApproval.get().getPendingScripts().collect() 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.