Check a plugin exists within a Jenkins Pipeline (Groovy)

大城市里の小女人 提交于 2019-12-10 13:38:46

问题


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?


回答1:


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'
}



回答2:


You could always use the old try/catch to make sure your build doesn't fail on this step :

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

However, I don't really see why slackSend command would not exist ? It can fail (e.g. if your Slack server is down) but as long as you have Slack Notification Plugin installed it should exist !



来源:https://stackoverflow.com/questions/39100232/check-a-plugin-exists-within-a-jenkins-pipeline-groovy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!