The purpose of sharing parts of a pipeline is to avoid redundancies, promoting reuse and facilitate maintenance. In the Jenkins this can be achieved through the Jenkins Shared Libraries feature as follow example.
- docker run -p 8080:8080 -p 50000:50000 jenkins/jenkins:alpine
- Access https://localhost:8080
- Copy and paste the admin password printed in the docker run console
- Select the install default plugins option
Create a Shared Library (respecting the directory structure)
- Example in the vars folder
- Access option Manage Jenkins/Configure System
- Add a Global Pipeline Libraries configuration
- Expected result:
- Configure the Pipeline Job with the pipeline script below
Pipeline script content:
genericPipeline {
appName = "application-demo"
echo "Executing in the ${appName} Jenkinsfile"
}
- Disable Use Groovy Sandbox
- Expected result:
- Run the job through the Build Now
- Verify the log
- Expected result:
- Access the job/Pipeline Syntax/Global Variables Reference
- Expected result: