Check if plugin exists in Jenkins pipeline (Groovy)

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

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

However, I do not want the build to break if slackSend does not exist. Is there any way to check this first?

+3
source share
2 answers

You may be able to wrap it conditional, although I'm not sure how Jenkins adds material to scripts ...

 if(this.respondsTo('slackSend')) { slackSend color: 'danger', message: 'Everything broke' } 
+1
source

You can always use the old try / catch to make sure your assembly does not work in this step:

 def resultBefore = currentBuild.result try { slackSend color: 'danger', message: 'Everything broke' } catch(err) { currentBuild.result = resultBefore } 

However, I really do not understand why the slackSend command slackSend not exist? It may fail (for example, if your Slack server is turned off), but as long as you installed Slack Notification Plugin , it must exist!

+1
source

Source: https://habr.com/ru/post/1266906/


All Articles