Skip to content

fix: log the payload that is actually sent to DingTalk - #403

Merged
BobDu merged 1 commit into
jenkinsci:mainfrom
BobDu:fix/log-actual-message-payload
Jul 28, 2026
Merged

fix: log the payload that is actually sent to DingTalk#403
BobDu merged 1 commit into
jenkinsci:mainfrom
BobDu:fix/log-actual-message-payload

Conversation

@BobDu

@BobDu BobDu commented Jul 28, 2026

Copy link
Copy Markdown
Member

What this fixes

The 发送的消息详情 (message details) line of the build log is the only place a user can see what the plugin actually posted to DingTalk. It has been logging the wrong object since the raw notification mode was added in c66a0df (2023-03).

Before that commit, the local variable message was the MessageModel, and the log line was correct. c66a0df needed a variable for the user's custom template and reused the same name for it, renaming the model to msgModel. Two call sites had to follow, and only one of them did:

String message = item.getMessage();                 // new: the raw template
MessageModel msgModel = item.isRaw() ? ... : ...;   // renamed: the payload

DingTalkUtils.log(listener, "发送的消息详情,%s", Utils.toJson(message));   // silently kept the old name
String msg = service.send(robotId, msgModel);                             // had to be updated

send(String, MessageModel) rejected a String, so the compiler forced that one. Utils.toJson(Object) accepted it, so the log line kept compiling with entirely different meaning. The result:

  • a built-in notification logs literally 发送的消息详情,null, because the template field is unset when the built-in message is used;
  • a raw notification logs the template before variable expansion, not what was sent.

Every DingTalkUtils.log call is gated on the global verbose setting, so this line only reaches the build log once someone turns detailed logging on — which is exactly when they are trying to diagnose a delivery problem and get null instead.

Nothing is lost by pointing it at the payload: the preceding 当前机器人信息 line already logs the notifier configuration, raw template included.

The local variable is renamed to rawMessage in the same change. That is what removes the trap rather than just its symptom: there is no longer a message in this scope for a future rename to collide with.

Testing done

mvn clean verify passes: 58 tests, plus spotless, access-modifier-checker, the enforcer import rules and spotbugs (0 findings).

DingTalkRunListenerLogTest runs a real build through JenkinsRule against a robot pointing at a closed port, then asserts on the build log — one case for the built-in message, one for a raw template. Both assert the log carries the expanded payload, which is what distinguishes it from the configuration line above it.

Both cases were checked by mutation: restoring Utils.toJson(message) makes them fail with [钉钉插件]发送的消息详情,null in the captured log, so they reproduce the reported behaviour rather than merely exercising the line.

Submitter checklist

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests that demonstrate the feature works or the issue is fixed

`send()` reused its local `message` variable for the user's raw template when raw
notification mode was added, but the "发送的消息详情" log line kept pointing at it. A
built-in notification therefore logs literally "发送的消息详情,null", and a raw
notification logs the template before variable expansion rather than the payload.

Only one of the two call sites that had to move was caught at the time: the compiler
rejected a String for `send(String, MessageModel)`, while `Utils.toJson(Object)` took it
silently. Renaming the local to `rawMessage` stops the two from colliding again.

The line only reaches the build log when the global verbose setting is on, i.e. exactly
when someone is diagnosing a problem. The preceding "当前机器人信息" line already logs the
notifier configuration including the raw template, so pointing this one at the payload
loses nothing.

Signed-off-by: BobDu <i@bobdu.cc>
@BobDu
BobDu merged commit 9ede269 into jenkinsci:main Jul 28, 2026
16 checks passed
@BobDu
BobDu deleted the fix/log-actual-message-payload branch July 29, 2026 06:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant