检查Jenkins Pipeline(Groovy)中是否存在插件

Dan*_*elM 6 groovy jenkins jenkins-plugins jenkins-pipeline

我想在管道中使用Slack Notification Plugin,这很简单:

slackSend color: 'danger', message: 'Everything broke'
Run Code Online (Sandbox Code Playgroud)

但是,如果slackSend不存在,我不希望构建中断。有没有办法先检查一下?

tim*_*tes 1

你也许可以将它包装在条件中,尽管我不确定 Jenkins 如何向脚本中添加内容......

if(this.respondsTo('slackSend')) {
    slackSend color: 'danger', message: 'Everything broke'
}
Run Code Online (Sandbox Code Playgroud)