REF LINK : https://github.com/pavankumar0077/Jenkins-Zero-To-Hero/tree/main/shared-libraries REF LINK : https://github.com/praveen1994dec/jenkins_shared_lib/tree/main/vars
- We hava 500 + microservices then that are individually developed and deployed, For every microservices we have to write jenkins file for the CI CD part.
- Now we you want to change the configuration like some commands in pipeline, Then going to 500 microservices and changing the config is very big task, Even you have wrote jenkins file for once and rest copies for 500 microservices.
- It is nothing but a commone or repetative or reusable code Ex: MAVEN BUILD IS same for all the applicaitons.
- Jenkins provide a concept called SHARED LIBRARIES, You need to put the reusable code as a library in GIT REPO anf reference the LIBRARY in our stage or pipeline or jenkins file
- Now we will take reference the library and use it in the jenkins file
@Library("my-shared-library) _This should to used to import the library and add the library details in the System or Tool settings in jenkins- Change in one place and it will changed in all the jenkins files.
-
- vars
- src
- resources
pipeline {
agent any
stages {
stage('Greetings') {
steps {
echo 'Hi Techie'
}
}
}
}
Step 1: Create a Git Repo for JENKINS SHARED LIBRARY
Step2 : Create vars folder --> Create the scripty --> maven-test.groovy (Ex) (Camalcase - helloWorld.groovy)
Step3: Congigure the shared library in jenkins --> Managme jenkins --> systems --> Global piple
Step4: In the jenkins file we have to import the shraed lib --> @Library("my-shared-library") _ Here _ is represents everything in the library
@Library("my-shared-library") _
pipeline {
agent any
stages {
stage('Greetings') {
steps {
helloWorld()
}
}
}
}
Here we are using helloWorld() --> IT IS FILE NAME NOT THE FUNCTION NAME

def call() {
sh 'mvn clean install'
}
@Library("my-shared-library") _
pipeline {
agent any
stages {
stage('Greetings') {
steps {
helloWorld()
}
}
stage('Maven Build') {
steps {
mvnBuild()
}
}
}
}
