I have a question related to sending a message to Slack from Jenkins (groovy script). Currently, I use SlackNotificationPlugin for sending messages to Slack and I'm trying to send line for the whole width of Slack, but instead of it, I can use only half of Slack width.
I use code below:
msg = readJSON text: """
{
"pretext": "<placeholder>",
"text": "<placeholder>",
"color": "good",
"mrkdwn_in": [
"pretext",
"text"
],
"fields": [
{
"title": "A field's title",
"value": "This field's valueaaaaaaaaaaaa valueaaaaaaaaaaaa valueaaaaaaaaaaaa valueaaaaaaaaaaaa valueaaaaaaaaaaaa valueaaaaaaaaaaaa valueaaaaaaaaaaaa",
"short": false
},
{
"title": "A short field's title",
"value": "A short field's value",
"short": true
},
{
"title": "A second short field's title",
"value": "A second short field's value",
"short": true
}
],
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Alternative hotel options*"
}
}
]
}
"""
msg.pretext = pretext.inspect()
msg.text = text.inspect()
slack_channel = partner_channel
slackSend(channel: slack_channel, color: 'good', attachments: "[${msg.toString()}]")
On the screenshot below you can see Packages Difference and it showed only on the half of the page.
I found a solution for this case and I tested it in Slack Block Kit Builder:
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "```{8}```"
}
}
]
}
It Slack Block Kit Builder, I can successfully send a message and use the whole space of slack:
In official documentation for Jenkins Slack Plugin (https://plugins.jenkins.io/slack/), I found that for sending blocks we can use the next construction:
blocks = [
[
"type": "section",
"text": [
"type": "mrkdwn",
"text": "Hello, Assistant to the Regional Manager Dwight! *Michael Scott* wants to know where you'd like to take the Paper Company investors to dinner tonight.\n\n *Please select a restaurant:*"
]
],
[
"type": "divider"
],
[
"type": "section",
"text": [
"type": "mrkdwn",
"text": "*Farmhouse Thai Cuisine*\n:star::star::star::star: 1528 reviews\n They do have some vegan options, like the roti and curry, plus they have a ton of salad stuff and noodles can be ordered without meat!! They have something for everyone here"
],
"accessory": [
"type": "image",
"image_url": "https://s3-media3.fl.yelpcdn.com/bphoto/c7ed05m9lC2EmA3Aruue7A/o.jpg",
"alt_text": "alt text for image"
]
]
]
slackSend(channel: "#general", blocks: blocks)
The mentioned code doesn't work for me I have nothing in Slack when I use block construction. Can somebody help me with it? I don't use any Bot User, I just want to send the output of Jenkins to Slack.
Thanks in advance.