Jenkins ShareLibrary 实践之自定义企业微信通知器

// 微信通知

def SendMessage(product,profile,srv_name,status){
    wrap([$class: 'BuildUser']){
        def WechatHook = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=9c69012a-3xxxxxxxxxxx-83b3axxxxx9"

        def reqBody = """{
            "msgtype": "markdown",
            "markdown": {
                "content": "### 构建信息:\n>- 产品线: **${product}**\n>- 发布环境:  **${profile}**\n>- 应用名称:  **${srv_name}**\n>- 构建发起人:  **${env.BUILD_USER}**\n>-  构建结果: **${status}**\n>- 持续时间: **${currentBuild.durationString}**\n- 构建日志:  [点击查看详情](${env.BUILD_URL})"
                    }
            }"""
    
        
        httpRequest acceptType: 'APPLICATION_JSON_UTF8', 
                consoleLogResponseBody: false, 
                contentType: 'APPLICATION_JSON_UTF8', 
                httpMode: 'POST', 
                ignoreSslErrors: true, 
                requestBody: "${reqBody}", 
                responseHandle: 'NONE', 
                url: "${WechatHook}",
                quiet: true
    }
}

需要注意的是,markdown消息体的格式。

转载地址