How does a `vars/` global step work?
BeginnerConceptShared libraries
Answer
Each vars/<name>.groovy file becomes a global variable named <name>. If it defines call(...), it can be invoked like a step.
// vars/trivyScan.groovy
def call(Map cfg = [:]) {
String severity = cfg.get('severity', 'HIGH,CRITICAL')
sh "trivy image --exit-code 1 --ignore-unfixed --severity ${severity} --input ${cfg.input}"
}
trivyScan(input: 'image.tar')
Other methods in the same file can be called as trivyScan.helper().
More on Shared libraries
What is the directory structure of a shared library?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?IntermediateGlobal vs folder-level vs ad hoc libraries: what is the security difference?Advanced