Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom message doesn't respect \n #135

Closed
FaizVisram opened this issue Sep 24, 2015 · 2 comments
Closed

Custom message doesn't respect \n #135

FaizVisram opened this issue Sep 24, 2015 · 2 comments

Comments

@FaizVisram
Copy link

I used an environment variable, ${SLACK_MESSAGE}, as the custom message, like this: SLACK_MESSAGE=Line1\nLine2\nLine3

The message itself had \n for new lines, but in Slack they got printed as literal "\n".

The environment variable was being loaded by EnvInject Plugin from a file.

I managed to fix it by having escaped new lines in the java properties file like this:

SLACK_MESSAGE=Line 1\
Line 2\
Lines 3
@samrocketman
Copy link
Member

From slack @bredman posted the following advice.

howdy, i'm a dev at Slack that works on ph's team and i was taking a look at that issue

I'm not super familiar with jenkins so I'm not able to test this theory easily but I believe I know what's happening with the newlines

I believe what's happening is that the Java JSON library is converting the newline character \n to the string literal "\n" here https://github.com/douglascrockford/JSON-java/blob/b0191a6acf6024b6b3efbd48dba8826ca79b950d/JSONObject.java#L1367

When you send a "\n" string through that method (which happens as part of the call to json.toString() in the plugin code) it will get converted to the string "\n" which our API will accept but render as a "\n" string literal in a Slack message

Does that make sense? Basically I think what you need to do is include newline literals in the messages to the Slack plugin and they will automatically get converted to the right strings for our API by the JSON library

The Slack plugin uses a different JSON library in Jenkins but it's likely the same issue. Contributions are welcome to potentially fix this issue. I don't actively develop this plugin but maintain pull requests and releases.

@samrocketman
Copy link
Member

After testing, the text box for custom messages is a multi-line text box. Therefore, this behavior is already supported. You need only press ENTER to get a new line without using the \n character. Closing this as invalid.

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

No branches or pull requests

2 participants