Jenkins Shared Libraries enable teams to centralize reusable Groovy scripts and pipeline logic in a single, version-controlled repository. By defining common steps—such as notifications, build commands, or deployment tasks—you can apply the DRY principle, reduce duplication, and ensure consistency across all your CI/CD pipelines.Documentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.

| Problem | Impact |
|---|---|
| Duplication | Hard to maintain multiple Jenkinsfiles |
| Inconsistency | Different pipelines drift over time |
| Complexity | Updates become error-prone |

- Better maintainability
- Unified pipeline behavior
- Easier on-boarding for new team members
Example: Centralizing a Welcome Message
Imagine your DevOps team wants every pipeline to greet developers:welcome.groovy step in your Shared Library:
Setting Up a Shared Library in Jenkins
To configure a Shared Library:- Create a Git repository dedicated to your shared steps and utilities.
- In Jenkins, go to Manage Jenkins → Configure System → Global Pipeline Libraries.
- Click Add and specify:
- Name: A unique identifier (e.g.,
kode-kloud-shared-library) - Default Version: Branch or tag (e.g.,
main) - Retrieval Method: Modern SCM → Git URL
- Advanced Options: Allow overriding the default version, load implicitly, etc.
- Name: A unique identifier (e.g.,
Make sure Jenkins has read access to your Git repository. If you use credentials, add them under Manage Jenkins → Credentials.

Repository Structure
A clear directory layout helps Jenkins locate your scripts:| Directory | Purpose |
|---|---|
| src | (Optional) Groovy/Java classes |
| vars | Required: global pipeline steps (camelCase) |
| resources | (Optional) static files accessed via libraryResource |

Configuring Global Pipeline Libraries
Once your repo is ready:- Manage Jenkins → Configure System → Global Pipeline Libraries.
- Add Library with:
- Name:
kode-kloud-shared-library - Default Version:
main - Load implicitly (optional)
- SCM: Git URL and credentials
- Name:

Using Your Shared Library
In each Jenkinsfile, include the@Library annotation to load your shared code:
welcome() step now references vars/welcome.groovy from your Shared Library, keeping pipelines concise and maintainable.