What if you could fix a bug once and have it instantly fixed everywhere your Jenkins pipelines run?
Why @Library annotation in Jenkins? - Purpose & Use Cases
Imagine you have many Jenkins pipelines, and each one needs to share the same helper scripts or functions. You copy and paste these scripts into every pipeline manually.
This manual copying is slow and risky. If you fix a bug or add a feature, you must update every pipeline separately. It's easy to forget one, causing inconsistent behavior and errors.
The @Library annotation lets you load shared code from a central place automatically. You write your helpers once, and all pipelines can use them instantly, always up to date.
def helper() { echo 'Hello' } // copied in every Jenkinsfile
@Library('shared-lib') _
helper.sayHello()You can maintain and improve shared pipeline code in one place, making your Jenkins setup cleaner, faster, and less error-prone.
A team uses @Library to share deployment steps across dozens of projects. When they update deployment logic, all projects get the fix immediately without touching each Jenkinsfile.
Manual code duplication causes errors and wastes time.
@Library loads shared code centrally for all pipelines.
This keeps Jenkins pipelines consistent and easy to maintain.