slack-plugin icon indicating copy to clipboard operation
slack-plugin copied to clipboard

Slack User ID from profile

Open TomTucka opened this issue 3 years ago • 4 comments

Your checklist for this issue

  • [2.235.4] Jenkins version

  • [2.40] Plugin version

Description

Hi,

If there any way to get the slack user ID from someone's Jenkins profile? I'd like to personal message people using the bot when specific things happen in certain builds

Cheers

TomTucka avatar Aug 20 '20 14:08 TomTucka

Use slackUserIdFromEmail

it will lookup the user's profile in Jenkins and use the slack API if it's not set there. Or whatever strategy you use. Some places store it in their directory information and have custom plugins to look it up.

timja avatar Aug 20 '20 15:08 timja

I'm not sure that the slackUserIdFromEmail step looks at the user's profile in Jenkins, I think it does a straight lookup via the slack API. If I'm reading the code correctly, it seems that profile setting is only used when notifying ChangeSet authors, which I don't have for my jobs.

I would like to send a slack notification to the user that manually started the build, based on this profile setting. Has anyone had luck with this?

Thanks!

pitaylor avatar May 21 '21 20:05 pitaylor

Update in case it's useful for anyone--I'm able to access the user property directly from a pipeline library function (in conjunction with the Build User Vars plugin):

wrap([$class: 'BuildUser']) {
    def user = User.getById(env.BUILD_USER_ID, false)
    def slackUserProperty = user?.getProperty(jenkins.plugins.slack.user.SlackUserProperty.class)
    def userId = slackUserProperty?.getUserId()
}

pitaylor avatar May 22 '21 17:05 pitaylor

@pitaylor @timja can we add this logic as default one directly on slackUserIdFromEmail class?

EliaBracciSumo avatar Jul 27 '23 12:07 EliaBracciSumo