slack-plugin: slackUserIdFromEmail() Doesn't Work

Version report

Jenkins 2.277.3 Slack Notification Plugin 2.48

Issue

Hi,

I got the same issue reported here https://github.com/jenkinsci/slack-plugin/issues/763, the func return null and no errors or debug informations are available.

Scopes

Here the scopes for my slack app. chat:write files:write users:read users:read.email

Token

token

Config as Code

slackNotifier:
    botUser: true
    room: "xxx-notifications"
    sendAs: "Jenkins"
    sendAsText: false
    slackUserIdResolver: "email"
    teamDomain: "xxx"
    tokenCredentialId: "slack-token"

thanks for your help. Below my code:

script {
  def lastCommiterEmail = sh(returnStdout: true, script: 'git log --format="%ae" | head -1').trim()
  def slackUserId = slackUserIdFromEmail("${lastCommiterEmail}")
  slackSend(botUser: true, tokenCredentialId: 'slack-token', color: "good", message: "<@${slackUserId} test message")
}

Result: result

Reproduction steps

I tested directly with my slack email in the slackUserIdFromEmail function but got the same result.

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Reactions: 2
  • Comments: 16 (5 by maintainers)

Most upvoted comments

We experience similar issue as posted above with the more recent versions as well:

  • Jenkins 2.440.2
  • Slack notification plugin 684.v833089650554

Enabled additional logging as described here but in the resulting log there are no details about the api calls being made by slack plugin to slack and their results. It only posts log messages like the one below:

Apr 23, 2024 3:39:19 PM FINE jenkins.plugins.slack.StandardSlackService

Posting: to #channel_name on :  {"attachments":[{"fallback":"null, message text","color":"#FFFF00","fields":[{"short":false,"value":"null, message text"}],"mrkdwn_in":["pretext","text","fields"]}],"link_names":"1","unfurl_links":"true","unfurl_media":"true","channel":"#channel_name","as_user":"true"}

Apr 23, 2024 3:39:20 PM FINE jenkins.plugins.slack.StandardSlackService
Posting succeeded

Any guidance on how to troubleshoot it further?

We ran into this same issue. We’re not able to resolve Slack userIds from email.

  • Jenkins --> 2.303.1 version
  • Slack Notification --> 2.48 version
  • The Slack email User ID Resolver is checked
  • The email I’m using with git operations is the one correctly associated with my Slack user
  • The custom bot we’re using has the right and required permissions, users:read and users:read.email

I’ve tried with a simple snippet like this one

def sendSlackNotification() {
  // test with 'slackUserIdFromEmail'
  def lastCommitterEmail = sh(returnStdout: true, script: 'git log --format="%ae" | head -1').trim()
  echo "commit author ${lastCommitterEmail}"
  def slackUserId = slackUserIdFromEmail("${lastCommitterEmail}")
  slackSend(color: "good", message: "@${slackUserId} 'slackUserIdFromEmail' message", channel: channel)

  // test with 'slackUserIdsFromCommitters'
  def userIds = slackUserIdsFromCommitters()
  def userIdsString = userIds.collect { "<@$it>" }.join(' ')
  slackSend(color: colorCode, message: "${userIdsString} 'slackUserIdsFromCommitters' message", channel: channel)
}

but I get nothing, see image below. image

If I use the Slack userId directly it does work i.e.

def sendSlackNotification() {
  // test with userId
  def userId = "@{my-slack-user-id}"
  slackSend(color: colorCode, message: "${userId} 'userId' message", channel: channel)
}

then it does work. Any hint? In master node’s /var/log/jenkins/jenkins.log file I can only see this warning, nothing more useful

2024-02-26 15:19:56.398+0000 [id=17689022]	WARNING	o.j.r.u.AnonymousClassWarnings#warn: Attempt to (de-)serialize synthetic class jenkins.plugins.slack.user.EmailSlackUserIdResolver$$Lambda$621/540202168 in file:/var/lib/jenkins/plugins/slack/WEB-INF/lib/slack.jar; see: https://jenkins.io/redirect/serialization-of-anonymous-classes/

Please provide more information, i.e. scopes, what resolution strategy you have configured in your global config?