Why is `sleep` or `waitUntil` inside an agent block wasteful?
BeginnerConceptScripted pipeline, Groovy & CPS
Answer
While a build sleeps inside node {} or a stage with an agent, it holds the executor and, on Kubernetes, keeps the pod with its CPU and memory requests reserved. Waiting for an external system (a deployment, an approval, a long test run elsewhere) should happen outside agent blocks when possible, or use webhooks such as waitForQualityGate that pause cheaply on the controller.
More on Scripted pipeline, Groovy & CPS
What does a scripted pipeline look like and when would you still write one?IntermediateWhat is CPS and why does Jenkins transform pipeline Groovy?AdvancedWhy does `java.io.NotSerializableException` happen in pipelines?AdvancedWhat does `@NonCPS` do and what are its rules?AdvancedWhy do some Groovy closures behave unexpectedly in pipelines, for example `list.each { }` or `sort`?AdvancedWhat is the `script` block in declarative, and what are its limits?Beginner