如何使用Groovy在Jenkins中发送最重要的通知?

时间:2018-12-10 19:12:06

标签: jenkins mattermost

在Jenkinsfile中是否有使用groovy发送最重要通知的指针?它类似于slacksend吗?

2 个答案:

答案 0 :(得分:0)

这对我有用:

mattermostSend(color: colorCode, icon: "https://jenkins.io/images/logos/jenkins/jenkins.png", message: message, channel: *channelname*, endpoint: *yourwebhookendpoint*)

答案 1 :(得分:0)

  1. 从插件管理器安装 Mattermost 通知插件。

  2. 脚本:

pipeline {
    agent any

    stages {
        stage('Build') {
      steps {
        script {
        try {
            mattermostSend (
            color: "#2A42EE",
            channel: 'Build_BOT',
            endpoint: 'https://linktomattermost.com/hooks/yuwrgjeh38246239jkfh', 
            message: "Build STARTED: ${env.JOB_NAME} #${env.BUILD_NUMBER} (<${env.BUILD_URL}|Link to build>)"
            )               
        sh '''
            mvn -B -DskipTests clean package
           '''
            } catch(e) {
                   currentBuild.result = "FAILURE"
            } finally {
                 if(currentBuild.result == "FAILURE") {
                    mattermostSend (
                       color: "#e00707",
                        channel: 'Build_BOT', 
                        endpoint: 'https://linktomattermost.com/hooks/yuwrgjeh38246239jkfh',
                         message: "Build FAILED: ${env.JOB_NAME} #${env.BUILD_NUMBER} (<${env.BUILD_URL}|Link to build>)"
                     )
                 } else {
                       mattermostSend (
                           color: "#00f514",
                            channel: 'Build_BOT', 
                            endpoint: 'https://linktomattermost.com/hooks/yuwrgjeh38246239jkfh',
                           message: "Build SUCCESS: ${env.JOB_NAME} #${env.BUILD_NUMBER} (<${env.BUILD_URL}|Link to build>)"
                            )
                        }                            
                    }
            }
        }
    }
    }
}