增加构建通知

This commit is contained in:
dengqichen 2025-11-27 18:46:07 +08:00
parent b9d5fbe360
commit cbe701a5af

View File

@ -648,6 +648,10 @@ public class JenkinsBuildServiceImpl extends BaseServiceImpl<JenkinsBuild, Jenki
}
}
} catch (org.springframework.orm.ObjectOptimisticLockingFailureException e) {
// 乐观锁冲突说明记录已被其他线程更新忽略即可
log.warn("构建通知记录乐观锁冲突,跳过处理: teamId={}, envId={}, buildId={}",
config.getTeamId(), config.getEnvironmentId(), build.getId());
} catch (Exception e) {
log.error("处理构建通知失败: teamId={}, envId={}, buildId={}",
config.getTeamId(), config.getEnvironmentId(), build.getId(), e);
@ -937,14 +941,16 @@ public class JenkinsBuildServiceImpl extends BaseServiceImpl<JenkinsBuild, Jenki
*/
private String uploadFileToWechat(NotificationChannel channel, String filePath) {
try {
// config 中获取 webhook URL
String webhookUrl = (String) channel.getConfig().get("webhookUrl");
if (webhookUrl == null || !webhookUrl.contains("key=")) {
log.error("无效的企业微信 webhook URL: {}", webhookUrl);
// config 中获取 key
if (channel.getConfig() == null) {
log.error("企业微信渠道配置为空: channelId={}", channel.getId());
return null;
}
String key = (String) channel.getConfig().get("key");
if (key == null || key.isEmpty()) {
log.error("企业微信渠道 key 为空: channelId={}", channel.getId());
return null;
}
String key = webhookUrl.substring(webhookUrl.indexOf("key=") + 4);
// 企业微信文件上传接口
String uploadUrl = "https://qyapi.weixin.qq.com/cgi-bin/webhook/upload_media?key=" + key + "&type=file";
@ -1000,7 +1006,8 @@ public class JenkinsBuildServiceImpl extends BaseServiceImpl<JenkinsBuild, Jenki
*/
private void sendWechatFileMessage(NotificationChannel channel, String mediaId) {
try {
String webhookUrl = (String) channel.getConfig().get("webhookUrl");
String key = (String) channel.getConfig().get("key");
String webhookUrl = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=" + key;
// 构建文件消息
Map<String, Object> message = new HashMap<>();