- Reuse the same notification logic across many repositories and jobs.
- Keep Jenkinsfiles small and focused on pipeline structure.
- Update notification behavior in one place rather than across dozens of Jenkinsfiles.
vars/.

shared-libraries). Initialize it and push an initial commit:
- Jenkins Shared Libraries documentation: https://www.jenkins.io/doc/book/pipeline/shared-libraries/

To create a step-style global function (so you can call it like a built-in step such as
sh or git), add a Groovy file under vars/ and define a call method.
Create the file vars/slackNotification.groovy in your shared-libraries repository.

vars/slackNotification.groovy. This exposes a slackNotification(...) step that your pipelines can call directly:
Define
call in vars/<name>.groovy to allow invoking the library step directly as <name>(...) from a Pipeline (this mirrors built-in steps like sh or git).- In Jenkins: Manage Jenkins → Configure System → Global Pipeline Libraries
- Add your
shared-librariesrepository with a name (for example,shared-libraries) so it can be referenced by name from any pipeline.
@Library annotation per-repository
- Add
@Library('<library-name>') _at the top of a Jenkinsfile to import the library for that pipeline.
- Review the Jenkins documentation on Shared Libraries to learn about loading strategies, caching, and versioning: https://www.jenkins.io/doc/book/pipeline/shared-libraries/
- Consider adding a
vars/slackNotification.txtfile to document usage/help for the step. - If your notification logic requires credentials or tokens (e.g., Slack webhook), use Jenkins Credentials and refer to them securely from your library code.
- Jenkins Shared Libraries — https://www.jenkins.io/doc/book/pipeline/shared-libraries/
- Jenkins Pipeline Syntax — https://www.jenkins.io/doc/book/pipeline/syntax/