A reusable pipeline code that can be shared across multiple Jenkins pipelines.
To start using this Shared Library in your Jenkins pipelines:
-
Add it as a Global Shared Library in your Jenkins instance:
- Go to Manage Jenkins > Configure System.
- Scroll down to Global Trusted Pipeline Libraries.
- Add a new library and configure:
- Name:
jenkins-shared-library
- Default version:
main
(or a specific branch/tag) - Repository URL:
<URL to this repository>
- Name:
-
Once added, you can reference this library in your Jenkinsfiles.
vars/
: Contains Groovy files defining custom pipeline steps. Each.groovy
file corresponds to a step callable in your Jenkinsfile.src/
: Contains helper classes and methods in a structured Java-like package format.resources/
: Stores non-code resources such as templates or configuration files.
To use this library in your Jenkins pipeline:
@Library('jenkins-shared-library') _
Place the above line at the top of your Jenkinsfile
to import the library.
Here’s an example Jenkinsfile
using this library:
@Library('jenkins-shared-library') _
pipeline {
agent any
stages {
stage('Example') {
steps {
exampleStep()
}
}
}
}
The exampleStep()
function is defined in vars/exampleStep.groovy
.