Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check a plugin exists within a Jenkins Pipeline (Groovy)

I want to use the Slack Notification Plugin in my pipelines, which is very easy:

slackSend color: 'danger', message: 'Everything broke'

However, I don't want the build to break if slackSend doesn't exist. Is there a way to check that first?

like image 856
DanielM Avatar asked Aug 23 '16 11:08

DanielM


People also ask

How do you check if a plugin is installed in Jenkins?

From the Jenkins home page: Click Manage Jenkins. Click Manage Plugins. Click on the Installed tab.

Where can I find plugins in Jenkins?

The Easiest Way to Get a Plugin For Jenkins Select Manage Jenkins > Manage Plugins. Here you should see a tab called Advanced, where there will be an option to upload the plugin. Most plugins can be installed immediately by clicking Install without restart.

Is Jenkins pipeline Groovy?

Within a Pipeline Project (read plugin), Jenkins introduces a domain-specific language (DSL) based on 'Groovy', which can be used to define a new pipeline as a script. The flow that would typically require many “standard” Jenkins jobs chained together, can be expressed as a single script.

What is the plugin for pipeline in Jenkins?

Pipelines are Jenkins jobs enabled by the Pipeline (formerly called “workflow”) plugin and built with simple text scripts that use a Pipeline DSL (domain-specific language) based on the Groovy programming language.


1 Answers

You might be able to wrap it in a conditional, though I'm not sure how Jenkins adds stuff to the scripts...

if(this.respondsTo('slackSend')) {
    slackSend color: 'danger', message: 'Everything broke'
}
like image 104
tim_yates Avatar answered Oct 25 '22 04:10

tim_yates