Interview Prep/Jenkins/Shared libraries

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.

All Jenkins questions Roadmap: Jenkins

More on Shared libraries