栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

蓝鲸平台扩展流水线构建成功插件

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

蓝鲸平台扩展流水线构建成功插件

1.邮件形式
1)引入gradle

2)在application 配置文件中添加配置信息

配置发邮件的服务器,此处使用qq邮箱发邮件

username:qq邮箱地址
password:为邮箱的授权码,不是qq密码

subprojects {
    group = "com.tencent.bk.devops.ci.notify"
    dependencies {
        api("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
        api("org.jetbrains.kotlin:kotlin-reflect")
        implementation("org.springframework.boot:spring-boot-starter-mail")
        testImplementation("junit:junit")
        testImplementation("org.springframework.boot:spring-boot-starter-test")
    }
}

3)EmailServiceImpl 中加入自己的实现

kotlin语言:

private fun sendMsg(emailNotifyPost: EmailNotifyMessageWithOperation) {
        val receivers = emailNotifyPost.getReceivers()
        val message = SimpleMailMessage()
        message.from = "1214000999@qq.com"
        message.setTo(*receivers?.toTypedArray())
        message.subject = emailNotifyPost.title
        message.text = emailNotifyPost.body
        val ccs = emailNotifyPost.getCc()
        message.setCc(*ccs?.toTypedArray())
        val bccs = emailNotifyPost.getBcc()
        message.setBcc(*bccs?.toTypedArray())
        try {
            javaMailSender!!.send(message)
            logger.info(this::class.toString() + "sendMsg 构建结果消息发送!")
        } catch (e: Exception) {
            logger.error(this::class.toString() + ".sendMsg 构建结果消息发送失败: " + e.printStackTrace())
        }

    }

4)BuildEndControl.finish() 构建完后的回调事件中加入调用邮件通知代码,可以通过rabbitmq 或者client发送http请求

2.企业微信发送消息
1)创建企业微信

2)配置apllication配置文件 分布式服务配置 notify项目的 ,单体配置 assembly项目的

wework:
  corpId:  企业id
  corpSecret: 秘钥 
  agentId: 应用id
  tempDirectory: # 保存待上传 wework 文件临时存储路径
  apiUrl: https://qyapi.weixin.qq.com # 企业微信服务端host,用于调用企业微信api接口
  safe: 0 # 表示是否是保密消息,0表示可对外分享,1表示不能分享且内容显示水印,默认为0
  enableDuplicateCheck: 0 # 表示是否开启重复消息检查,0表示否,1表示是,默认0
  duplicateCheckInterval: # 表示是否重复消息检查的时间间隔,默认1800s,最大不超过4小时
  enableIdTrans: 0 # 表示是否开启id转译,0表示否,1表示是,默认0。仅第三方应用需要用到,企业自建应用可以忽略。

corpid:

agentId,corpSecret(点击查看):

3)企业微信 蓝鲸1.5已实现所以只需调用即可

在BuildEndControl.finnish() 中编写调用代码

var receivers:String
        var receiverType=WeworkReceiverType.single
        var textType= WeworkTextType.text
        var message :String
        var notifyMsg= pipelineSettingService.getSetting(pipelineId)!!
        //获取构建成功通知模板
        if (!buildStatus.isCancel() && !buildStatus.isFailure()) {
//             receivers=notifyMsg?.successReceiver;
             message=notifyMsg?.successContent;
        }else{
//            receivers=notifyMsg?.failReceiver;
            message=notifyMsg?.failContent;
        }

//        pipelineRepositoryService.getPipelineInfo(projectId, pipelineId, buildInfo.channelCode)
        val map: MutableMap = HashMap()
        map["BK_CI_BUILD_NUM"] = buildInfo.buildNum?.toString()
        map["BK_CI_BUILD_TOTAL_TIME"] = (buildInfo.endTime?:0-(buildInfo.startTime?:0)).toString()
        map["BK_CI_PROJECT_NAME_CN"] = "xm"
        map["BK_CI_PIPELINE_NAME"] = "12"
        map["BK_CI_START_USER_NAME"] = buildInfo.startUser
        val strSubstitute = StrSubstitutor(map)
        message=strSubstitute.replace(message)

        try {
            val result =client.get(BuildNotifyResource::class).sendWeworkTextNotify(receivers?:"",receiverType,textType,message)
            if (result.isOk() && result.data != null) {
                LOG.info("SENT MSG TO  WEWORD SUCCESS! ")
            }
        }catch (e:Exception){
            LOG.error("${this::class.java.toString()} :SENT MSG TO  WEWORD ERROR: ${e.localizedMessage}")

        }
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/704988.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号