Using the @Library Annotation in Jenkins Pipelines
📖 Scenario: You are working on a Jenkins pipeline project where you want to reuse shared code stored in a separate Git repository. Jenkins provides a way to include shared libraries using the @Library annotation.This project will guide you step-by-step to create a simple Jenkins pipeline script that uses the @Library annotation to load a shared library and call a function from it.
🎯 Goal: Build a Jenkins pipeline script that uses the @Library annotation to load a shared library named my-shared-lib and calls a function sayHello() from that library.
📋 What You'll Learn
Create a Jenkins pipeline script with the
@Library annotationDeclare the shared library name exactly as
my-shared-libCall the
sayHello() function from the shared libraryPrint the output of
sayHello() in the pipeline💡 Why This Matters
🌍 Real World
In real Jenkins projects, shared libraries help teams reuse common pipeline code, reducing duplication and errors.
💼 Career
Understanding how to use the @Library annotation is essential for Jenkins pipeline developers and DevOps engineers to write modular and maintainable pipelines.
Progress0 / 4 steps