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') { ... }.
More on Shared libraries
What is the directory structure of a shared library?BeginnerHow does a `vars/` global step work?BeginnerWhat goes in `src/` and how is it used?IntermediateHow do classes in `src/` call pipeline steps?IntermediateWhat is `libraryResource` used for?IntermediateWhat are the ways to load a library in a Jenkinsfile?Intermediate