Scripting Plugins in Jenkins Pipelines

DZone 's Guide to

Scripting Plugins in Jenkins Pipelines

Check out how the Snippet Generator tool can create an easier way to work with the many Jenkins plugins.

· DevOps Zone ·
Free Resource


When Jenkins first introduced Pipelines, the DevOps community recognized a major step forward in integrating with CI/CD solutions: The ability to create jobs either via the usual GUI or using a Groovy-based DSL meant DevOps shops could have greater control with their development workflows.  A "Jenkinsfile" (similar in nature to a Dockerfile) contains the script and can be treated as code, allowing it to be put into version control for obvious benefits.

Then Blue Ocean was announced as a way to visualize these pipeline jobs, proposing to make it easier still for shops to create pipelines in Jenkins, going so far as promising CD that "is no longer for the experts."

However, while this sounds nice on paper, one area that continues to lag with respect to Blue Ocean is that while various steps and stages can be selected in a visual manner, users are still left to write blocks of scripts to ultimately accomplish what the pipeline is supposed to do. And with a plethora of plugins now available to be used by Jenkins — each with its own commands and nuances — there is no nice way for Blue Ocean to "just know" how to use each plugin or how to guide users in their use.

So What Can We Do?

Fortunately, there is a way to help ease the learning curve for plugins with a handy feature in Jenkins.

Enter Jenkins' "Snippet Generator."

To access this, click on any pipeline that you have created (if you haven't, go ahead and create one; it doesn't require much information to setup).

From here, do the following:

  1. Click "Pipeline Syntax" on the left-hand side of the screen.

  2. Select which step you'd like to explore from the dropdown (these are augmented by the plugins installed, so if you're curious about a plugin, this is where it will appear).

  3. The step's arguments and options will appear. Here, you can set the values to be whatever you wish.

  4. When finished setting the options, click "Generate Pipeline Script."

  5. The corresponding pipeline script appears in the text area below the button. This script can be inserted directly into a Jenkinsfile for immediate use.

And that's it!

You will also notice when using the Snippet Generator that on the left-hand side of that screen there are additional helpful links to references and related documentation.


Jenkins' pipeline DSL is super handy to anyone operating in a DevOps environment.  Learning a slew of Jenkins plugins' ins and outs, however, can be tedious.  The Snippet Generator makes this task just a little easier.  Try it and see!

devops ,jenkins ci ,dsl ,jenkinsfile ,blue ocean ,pipeline ,script

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}