Jenkins Joy: Shared library for Jenkins Declarative Pipeline

Since the introduction of the Jenkins Declarative Pipeline syntax (as opposed to the Scripted Pipeline syntax) the concept of a shared library has become more important as we are otherwise restricted to the sections of the pipeline model. So we’ll make a basic set-up with a call to a defined step in a shared library.

A shared library called “jdriven” is configured globally in Jenkins (see link to at the end on how to do that). It has a defined step showQuote defined in it’s own file on branch “blog/shared-lib-example”


A basic Jenkinsfile defining the pipeline, calling step showQuote from the shared library:

More information on the Declarative Pipeline and the use of Shared Libraries at

Written using Jenkins 2.32.2 and Pipeline plugin 2.5

2 thoughts on “Jenkins Joy: Shared library for Jenkins Declarative Pipeline

  1. Good example, how can we get a return value from a method in a shared library with declarative syntax ? like this :
    String word = new aClasse().getWord();

    • if you change the shared library code from:
      println quotes.get(new Random().nextInt(quotes.size()))
      return quotes.get(new Random().nextInt(quotes.size()))

      then in the steps use it as:
      script{ x = showQuote() }
      echo “x is $x”
      the variable x will have the returned quote.



Leave a Reply

Your email address will not be published. Required fields are marked *