CodeshipHannah Inman6 min readintermediate
Jenkins World Speaker Highlight: Extending your Pipeline with Shared Libraries, Global Functions and External Code
Summary
A practical walkthrough of Jenkins shared libraries: repository layout, global vs scoped loading, a simple Groovy var (gbuild) that wraps Gradle, and the steps to configure and use the library in a pipeline.
- Shared libraries let you factor out reusable Groovy code for Jenkins Pipelines without writing a plugin.
- Library repo must contain `vars/`, `src/`, and `resources/` directories; `vars` is the only place to expose functions to Declarative pipelines.
- Define a global library in *Manage Jenkins → Configure System → Global Pipeline Libraries* and point it at a Git repo.
- Load the library in a Jenkinsfile with `@Library('myLib') _` (underscore imports all vars).
Encapsulating build steps in shared libraries reduces duplication across many pipelines, enforces consistency, and enables declarative pipelines to run scripted logic safely. This is essential for scaling CI/CD in large orgs.
5/10