Interview Prep/Jenkins/Shared libraries

How should a global step accept arguments?

IntermediateConceptShared libraries
Answer

Use a Map with defaults and validate required keys, which keeps calls readable and backward compatible.

def call(Map args = [:]) {
  def cfg = [namespace: 'default', timeout: '120s'] + args
  if (!cfg.deployment) { error "k8sDeploy: 'deployment' is required" }
  sh "kubectl -n ${cfg.namespace} rollout status deploy/${cfg.deployment} --timeout=${cfg.timeout}"
}

A closure argument (def call(Map cfg, Closure body)) lets you write wrapper steps such as withVault(path: 'x') { ... }.

All Jenkins questions Roadmap: Jenkins

More on Shared libraries