@@ -103,7 +103,7 @@ private BuildStatusEnum getBuildStatus(NoticeOccasionEnum noticeOccasion) {
103
103
case NOT_BUILT :
104
104
return BuildStatusEnum .NOT_BUILT ;
105
105
default :
106
- return null ;
106
+ return BuildStatusEnum . UNKNOWN ;
107
107
}
108
108
}
109
109
@@ -244,10 +244,21 @@ private void send(Run<?, ?> run, TaskListener listener, NoticeOccasionEnum notic
244
244
String projectUrl = job .getAbsoluteUrl ();
245
245
246
246
// 构建信息
247
- BuildStatusEnum statusType = getBuildStatus (noticeOccasion );
248
247
String jobName = run .getDisplayName ();
249
248
String jobUrl = rootPath + run .getUrl ();
250
249
String duration = run .getDurationString ();
250
+ BuildStatusEnum statusType = getBuildStatus (noticeOccasion );
251
+
252
+ // 设置环境变量
253
+ envVars .put ("EXECUTOR_NAME" , executorName == null ? "" : executorName );
254
+ envVars .put ("EXECUTOR_MOBILE" , executorMobile == null ? "" : executorMobile );
255
+ envVars .put ("PROJECT_NAME" , projectName );
256
+ envVars .put ("PROJECT_URL" , projectUrl );
257
+ envVars .put ("JOB_NAME" , jobName );
258
+ envVars .put ("JOB_URL" , jobUrl );
259
+ envVars .put ("JOB_DURATION" , duration );
260
+ envVars .put ("JOB_STATUS" , statusType .getLabel ());
261
+
251
262
List <ButtonModel > btns = Utils .createDefaultBtns (jobUrl );
252
263
List <String > result = new ArrayList <>();
253
264
List <DingTalkNotifierConfig > notifierConfigs = property .getAvailableNotifierConfigs ();
@@ -261,43 +272,47 @@ private void send(Run<?, ?> run, TaskListener listener, NoticeOccasionEnum notic
261
272
262
273
String robotId = item .getRobotId ();
263
274
String content = item .getContent ();
275
+ String message = item .getMessage ();
264
276
boolean atAll = item .isAtAll ();
265
277
Set <String > atMobiles = item .resolveAtMobiles (envVars );
266
278
267
279
if (StringUtils .isNotEmpty (executorMobile )) {
268
280
atMobiles .add (executorMobile );
269
281
}
270
282
271
- String text = BuildJobModel .builder ().projectName (projectName ).projectUrl (projectUrl )
272
- .jobName (jobName )
273
- .jobUrl (jobUrl )
274
- .statusType (statusType )
275
- .duration (duration )
276
- .executorName (executorName )
277
- .executorMobile (executorMobile )
278
- .content (
279
- envVars .expand (content ).replace ("\\ \\ n" , "\n " )
280
- )
281
- .build ()
282
- .toMarkdown ();
283
-
284
- String statusLabel = statusType == null ? "unknown" : statusType .getLabel ();
285
-
286
- MessageModel message = MessageModel .builder ()
287
- .type (MsgTypeEnum .ACTION_CARD )
288
- .atAll (atAll )
289
- .atMobiles (atMobiles )
290
- .title (
291
- String .format ("%s %s" , projectName , statusLabel )
292
- )
293
- .text (text )
294
- .btns (btns )
295
- .build ();
283
+ MessageModel msgModel =
284
+ item .isRaw () ? MessageModel .builder ()
285
+ .type (MsgTypeEnum .MARKDOWN )
286
+ .text (
287
+ envVars .expand (message ).replace ("\\ \\ n" , "\n " )
288
+ ).build ()
289
+ : MessageModel .builder ()
290
+ .type (MsgTypeEnum .ACTION_CARD )
291
+ .atAll (atAll )
292
+ .atMobiles (atMobiles )
293
+ .title (
294
+ String .format ("%s %s" , projectName , statusType .getLabel ())
295
+ )
296
+ .text (
297
+ BuildJobModel .builder ().projectName (projectName ).projectUrl (projectUrl )
298
+ .jobName (jobName )
299
+ .jobUrl (jobUrl )
300
+ .statusType (statusType )
301
+ .duration (duration )
302
+ .executorName (executorName )
303
+ .executorMobile (executorMobile )
304
+ .content (
305
+ envVars .expand (content ).replace ("\\ \\ n" , "\n " )
306
+ )
307
+ .build ()
308
+ .toMarkdown ()
309
+ )
310
+ .btns (btns ).build ();
296
311
297
312
DingTalkUtils .log (listener , "当前机器人信息,%s" , Utils .toJson (item ));
298
313
DingTalkUtils .log (listener , "发送的消息详情,%s" , Utils .toJson (message ));
299
314
300
- String msg = service .send (robotId , message );
315
+ String msg = service .send (robotId , msgModel );
301
316
302
317
if (msg != null ) {
303
318
result .add (msg );
0 commit comments