What is `libraryResource` used for?
IntermediateConceptShared libraries
Answer
It reads a file from the library's resources/ folder as a string: pod templates, shell scripts, config templates, sonar properties. Combine with writeFile to use it in the workspace.
def script = libraryResource 'scripts/notify.sh'
writeFile file: 'notify.sh', text: script
sh 'bash notify.sh'
podTemplate(yaml: libraryResource('pods/maven.yaml')) { node(POD_LABEL) { ... } }
This keeps scripts out of Groovy strings, where quoting is painful.
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 are the ways to load a library in a Jenkinsfile?IntermediateGlobal vs folder-level vs ad hoc libraries: what is the security difference?Advanced