Closed IdanAdar closed 5 years ago
If you pass all of the variable in pipeline it will work i.e.
def slackResponse = slackSend(channel: "myChannel", color: '#199515',message: "*$JOB_NAME*, <$BUILD_URL|Build #$BUILD_NUMBER>: my message",botUser: true, tokenCredentialId: myBotUserToken)
Thanks.
In the Jenkinsfile, I changed to this:
def slackResponse = slackSend(channel: "myChannel", color: '#199515',message: "*$JOB_NAME*, <$BUILD_URL|Build #$BUILD_NUMBER>: my message.")
slackSend(channel: "${slackResponse.threadId}", color: '#199515',message: "*$JOB_NAME*, <$BUILD_URL|Build #$BUILD_NUMBER>: my message 1.", botUser: true, tokenCredentialId: "slackbot-token-for-writing-into-slack-threads")
The message is written, but the thread is not created still.
you need to do it on both slackSends, looks like you only did it on one
if I add those two to the original slackSend then it is again not sent to Slack. It's basically the same same issue as in (2).
is the bot invited to your channel?
Yes.
Add a log recorder for this class: https://github.com/jenkinsci/slack-plugin/blob/master/src/main/java/jenkins/plugins/slack/StandardSlackService.java#L194 Needs fine level logging, see if that helps
Sorry, didn't understand what is the exact value I should put in Logger:
jenkins.plugins.slack.StandardSlackService
The log (some wording redacted):
Jun 17, 2019 4:58:23 PM FINE jenkins.plugins.slack.StandardSlackService
Posting: to myChannel on **** using https://slack.com/api/chat.postMessage?token=****&channel=myChannel&link_names=1&as_user=true&attachments=%5B%7B%22fallback%22%3A%22*Common-Updater-Repositories*%2C+%3Chttps%3A%2F%2F****%2Fjob%2FCommon-Updater-Repositories%2F96%2F%7CBuild+%2396%3E%3A+Starting+to+update+dependnecies.%22%2C%22color%22%3A%22%23199515%22%2C%22fields%22%3A%5B%7B%22short%22%3Afalse%2C%22value%22%3A%22*Common-Updater-Repositories*%2C+%3Chttps%3A%2F%2F****%2Fjob%2FCommon-Updater-Repositories%2F96%2F%7CBuild+%2396%3E%3A+Starting+to+update+dependnecies.%22%7D%5D%2C%22mrkdwn_in%22%3A%5B%22pretext%22%2C%22text%22%2C%22fields%22%5D%7D%5D: [{"fallback":"*Common-Updater-Repositories*, <https://****/job/Common-Updater-Repositories/96/|Build #96>: Starting to update dependnecies.","color":"#199515","fields":[{"short":false,"value":"*Common-Updater-Repositories*, <https://****/job/Common-Updater-Repositories/96/|Build #96>: Starting to update dependnecies."}],"mrkdwn_in":["pretext","text","fields"]}] #199515
Jun 17, 2019 4:58:23 PM FINE jenkins.plugins.slack.StandardSlackService
Posting succeeded
It says success, but nothing is actually posted.
There's a fix on master which should give the actual error. I'll release it now
Can you try with version 2.25 please
The build log shows:
Slack Send Pipeline step running, values are - baseUrl: <empty>, teamDomain: ****, channel: ****, color: #199515, botUser: true, tokenCredentialId: slackbot-token-for-writing-into-slack-threads, iconEmoji <empty>, username <empty>
ERROR: Slack notification failed with exception: {"ok":false,"error":"not_in_channel","warning":"missing_charset","response_metadata":{"warnings":["missing_charset"]}}
ERROR: Slack notification failed. See Jenkins logs for details.
And:
Java.lang.NullPointerException: Cannot get property 'threadId' on null object
The log shows:
Jun 17, 2019 6:13:38 PM WARNING jenkins.plugins.slack.StandardSlackService publish
Response Code: 200
But the channel does have a notification that the bot user was added.
added an integration to this channel: certsbot
that's different, you need to invite the bot user to the channel
/invite @jenkins-bot #channel-name
Okay, that worked and now the first message is posted by the app, but messages into the thread fail:
Build log:
Slack Send Pipeline step running, values are - baseUrl: <empty>, teamDomain: ***, channel: C4GEHN657:1560785714.005200, color: #199515, botUser: true, tokenCredentialId: slackbot-token-for-writing-into-slack-threads, iconEmoji <empty>, username <empty>
ERROR: Slack notification failed with exception: {"ok":false,"error":"invalid_thread_ts","warning":"missing_charset","response_metadata":{"messages":["[ERROR] 0 is not a valid thread_ts"],"warnings":["missing_charset"]}}
ERROR: Slack notification failed. See Jenkins logs for details.
System log:
Jun 17, 2019 6:35:37 PM FINE jenkins.plugins.slack.StandardSlackService
Posting: to C4GEHN657 on ibm-cloudplatform using https://slack.com/api/chat.postMessage: [{"fallback":"*Common-Updater-Repositories*, <https://***/job/Common-Updater-Repositories/99/|Build #99>: certificate-manager-service-api - Common code dependencies match the latest package versions. Nothing to update.","color":"#199515","fields":[{"short":false,"value":"*Common-Updater-Repositories*, <https://***/job/Common-Updater-Repositories/99/|Build #99>: certificate-manager-service-api - Common code dependencies match the latest package versions. Nothing to update."}],"mrkdwn_in":["pretext","text","fields"]}] #199515
Jun 17, 2019 6:35:37 PM WARNING jenkins.plugins.slack.StandardSlackService publish
Slack post may have failed. Response: {"ok":false,"error":"invalid_thread_ts","warning":"missing_charset","response_metadata":{"messages":["[ERROR] 0 is not a valid thread_ts"],"warnings":["missing_charset"]}}
Jun 17, 2019 6:35:37 PM WARNING jenkins.plugins.slack.StandardSlackService publish
Response Code: 200
can you echo the thread id? it seems to think its sending 0 which isn't right
It seems to print a full value: *** thread id is: C4GEHN657:1560786919.005300
But fails with:
Slack Send Pipeline step running, values are - baseUrl: <empty>, teamDomain: ***, channel: C4GEHN657:1560786919.005300, color: #199515, botUser: true, tokenCredentialId: slackbot-token-for-writing-into-slack-threads, iconEmoji <empty>, username <empty>
ERROR: Slack notification failed with exception: {"ok":false,"error":"invalid_thread_ts","warning":"missing_charset","response_metadata":{"messages":["[ERROR] 0 is not a valid thread_ts"],"warnings":["missing_charset"]}}
ERROR: Slack notification failed. See Jenkins logs for details.
System log:
Jun 17, 2019 6:55:40 PM FINE jenkins.plugins.slack.StandardSlackService
Posting: to C4GEHN657 on ibm-cloudplatform using https://slack.com/api/chat.postMessage: [{"fallback":"*Common-Updater-Repositories*, <https://wcp-certificate-manager-jenkins.swg-devops.com/job/Common-Updater-Repositories/100/|Build #100>: certificate-manager-service-api - Common code dependencies match the latest package versions. Nothing to update.","color":"#199515","fields":[{"short":false,"value":"*Common-Updater-Repositories*, <https://wcp-certificate-manager-jenkins.swg-devops.com/job/Common-Updater-Repositories/100/|Build #100>: certificate-manager-service-api - Common code dependencies match the latest package versions. Nothing to update."}],"mrkdwn_in":["pretext","text","fields"]}] #199515
Jun 17, 2019 6:55:40 PM WARNING jenkins.plugins.slack.StandardSlackService publish
Slack post may have failed. Response: {"ok":false,"error":"invalid_thread_ts","warning":"missing_charset","response_metadata":{"messages":["[ERROR] 0 is not a valid thread_ts"],"warnings":["missing_charset"]}}
Jun 17, 2019 6:55:40 PM WARNING jenkins.plugins.slack.StandardSlackService publish
Response Code: 200
I've reproduced that, and tested on 2.24, it works on the old version. Downgrade and I'll try get a fix out tonight / tomorrow
Many thanks @timja. Looking forward to 2.26.
It has been released now
Awesome. Works. :)
Your checklist for this issue
[x] Jenkins version: 2.164.3
[x] Plugin version: 2.24
[x] OS: Linux
Description
Until now, in order to post messages from Jenkins to Slack, I used the Jenkins CI App provided by Slack. I generated a token, saved this token as a Jenkins credential and used it in the Global Slack Notifier Settings. I then use the slackSend step to write messages in various channels.
Now I want to also create a thread for a message in whichever channel and write into it. In order to do this using slackSend, I need to create a bot and use its oauth token.
However it seems I can only use one of these at a time? The settings only allow for 1 credential to be set and used.
e.g.
When using the Jenkins CI App the message is created but the thread does not. When using the bot use the message is not created at all.