- Defining library functions (e.g., Slack notifications)
- Adding a Shared Library in Jenkins
- Referencing and importing library code in pipelines
- Fetching third-party dependencies with
@Grab - Bundling and retrieving resource files

1. Example: Slack Notification Script
Place this Groovy function undervars/notify.groovy in your Shared Library to send build status updates to Slack:
| Build Status | Color Code |
|---|---|
| SUCCESS | #47ec05 |
| UNSTABLE | #d5ee0d |
| FAILED/OTHER | #ec2805 |
2. Register the Shared Library
- Go to Manage Jenkins → Configure System.
- Scroll to Global Pipeline Libraries.
By default, libraries run in Jenkins’ Groovy sandbox.
Disabling the sandbox allows static calls,
Disabling the sandbox allows static calls,
@Grab, and advanced APIs but bypasses script-security checks.| Field | Description | Example |
|---|---|---|
| Name | Unique identifier for the library | DasherSharedLib |
| Default version | Git branch or tag used when unqualified | main |
| Load implicitly | Auto-load library without @Library | Off |
| Allow version override | Permit @Library('name@branch') to select alternate branches | Enabled |
| Include in job recent changes | Trigger pipelines when the library code changes | Opt-in |
| Retrieval method | SCM plugin to fetch the library (Git, SVN, etc.) | Git |
| Project repository | Repository URL | https://github.com/... |
- Click Add under Global Pipeline Libraries.
- Fill out the form using the table above.
- Click Apply and Save.


3. Reference the Library in Your Pipeline
Add the library at the top of yourJenkinsfile:
3.1 Fetching Third-Party Dependencies
Trusted Shared Libraries can include@Grab annotations to pull Maven artifacts:
libraryResource:
@Grab and libraryResource require the library to run outside the sandbox.Sandboxed mode will block these calls with security exceptions.
4. Next Steps
- Create a pipeline to invoke your Shared Library methods.
- Explore Pipeline Syntax for advanced usage.