slack-plugin
slack-plugin copied to clipboard
Slack message being truncated around 2048 chars
Your checklist for this issue
- [x] Jenkins version - 2.257
- [x] Plugin version - 2.42
- [x] OS - Linux
Description
Hi, we are observing an issue with messages sent to Slack being truncated on 2048 chars. Per quick search I've found this issue #390 , where it was said that message size should be 4000. Could you tell me please, this observed truncation is a new limit for message size, or previous issue was really not fixed?
🤷
what are you trying to do that makes it so long?
Check the slack api limits, different fields have different limits
We are sending environments provision reports from Jenkins to Slack. Usually there are small environments being provisioned with 1-3-5 servers, so report is short, but from time to time we need to provision big environments with 40-50 servers in it, and provision reports for such environments are being cut, so developers and testers need to go to the Jenkins to get all the details. As for API limits, per https://api.slack.com/changelog/2018-04-truncating-really-long-messages Slack accepts messages up to 40000 chars, so 2k limit is quite below that, and can be increased.
Not really sure, happy to take a contribution to fix, best way would be to reproduce with the slack api, adjust the log levels ( details in readme) and see what request the plugin is making and do the same with curl / postman
appears to be the same as before.. https://github.com/jenkinsci/slack-plugin/issues/390
Need to update code https://github.com/jenkinsci/slack-plugin/blob/master/src/main/java/jenkins/plugins/slack/StandardSlackService.java#L363
to include attachment.put("text", message);
and not sure if you still need the following (in same method):
JSONObject field = new JSONObject();
field.put("short", false);
field.put("value", message);
JSONArray fields = new JSONArray();
fields.add(field);
I don't have time to test these changes and to see if it breaks any of the "formatted" message logic. But feel free to yourself!
The show more works with the above changes.. not sure what/if it breaks other features..
diff --git a/src/main/java/jenkins/plugins/slack/StandardSlackService.java b/src/main/java/jenkins/plugins/slack/StandardSlackService.java
index 13fa564..2849b16 100755
--- a/src/main/java/jenkins/plugins/slack/StandardSlackService.java
+++ b/src/main/java/jenkins/plugins/slack/StandardSlackService.java
@@ -352,14 +352,15 @@ public class StandardSlackService implements SlackService {
}
private JSONArray prepareAttachments(String message, String color) {
- JSONObject field = new JSONObject();
- field.put("short", false);
- field.put("value", message);
+ //JSONObject field = new JSONObject();
+ //field.put("short", false);
+ //field.put("value", message);
JSONArray fields = new JSONArray();
- fields.add(field);
+ //fields.add(field);
JSONObject attachment = new JSONObject();
+ attachment.put("text", message);
attachment.put("fallback", message);
attachment.put("color", color);
attachment.put("fields", fields);
Unfortunately, my Java skills are very low, so I can only patiently wait for someone to fix this :)
Ran into this limitation and there is actually a simple workaround: instead of using a message
:
slackSend(channel: channel, color: color, message: message)
you can use a single attachment:
def attachments = [
[
text: message,
fallback: 'Fallback',
color: color
]
]
slackSend(channel: channel, attachments: attachments)
so what's the character limit on attachments?