jenkinsci / slack-plugin

A Jenkins plugin for posting notifications to a Slack channel
https://plugins.jenkins.io/slack/
MIT License
670 stars 413 forks source link

Slack User ID from profile #721

Open TomTucka opened 4 years ago

TomTucka commented 4 years ago

Your checklist for this issue

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

timja commented 4 years ago

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.

pitaylor commented 3 years ago

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 commented 3 years ago

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()
}
elia-bracci-hs commented 1 year ago

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