Skip to content

lapozzo/jenkins-shared-library-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 

Repository files navigation

Jenkins Shared Library Example

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.

Start up Jenkins

  • 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

Configure the shared library in the Jenkins

  • Access option Manage Jenkins/Configure System
  • Add a Global Pipeline Libraries configuration
  • Expected result:

Shared library configuration

Create a Pipeline Job

  • 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:

Create a Pipeline Job

Run the Pipeline Job

  • Run the job through the Build Now
  • Verify the log
  • Expected result:

Job execution log

Accessing the generic pipeline help

  • Access the job/Pipeline Syntax/Global Variables Reference
  • Expected result:

Job execution log

About

Simple example using Jenkins Shared Library

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages