-
Notifications
You must be signed in to change notification settings - Fork 413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
slackUserIdsFromCommitters() returns empty list for pipeline projects #930
Comments
With some more tweaks to the above code, I was able to create a EmailSlackUserIdResolver with appropriate HttpClient and Autorization tokens, the rest api to slack works and the user ids was resolved. |
Hi @enaess, we have the same problem on our Jenkins instance -- can you please post your working solution? |
Try pasting in the following into your Jenkins pipeline script to see if fixes it // Until slack-plugin fixes the slackUserIdsFromCommitters() function, see: https://github.com/jenkinsci/slack-plugin/issues/930
// this does require a few approvals in the script sandbox.
@NonCPS
def getSlackUsers(changesets) {
def resolver = new jenkins.plugins.slack.user.EmailSlackUserIdResolver(
"${env.BOT_CRED_PSW}",
jenkins.plugins.slack.HttpClient.getCloseableHttpClient(null))
resolver.setMailAddressResolvers(hudson.tasks.MailAddressResolver.all())
return resolver.resolveUserIdsForChangeLogSets(currentBuild.getChangeSets()).toSet().collect { "<@$it>" }.join(', ')
} Usage: in the failure block of your pipeline: failure {
script {
def userIdsString = getSlackUsers(currentBuild.changeSets)
if (!userIdsString.isEmpty()) {
slackSend (color: '#FF0000',
channel: '#your-slack-channel-here',
message: "FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (<${env.BUILD_URL}|Open>), Committers: $userIdsString")
}
.... |
Thank you @enaess! |
Jenkins and plugins versions report
Environment
What Operating System are you using (both controller, and any agents involved in the problem)?
Ubuntu Linux 22.04 for all systems involved
Reproduction steps
Expected Results
The results after calling
slackUserIdsFromCommitters()
should return a list, I shouldn't have to resolve the changeSets myself and call this.Actual Results
slackUserIdsFromCommitters() seems to always return an empty list. No log messages are seen when I comment out the section from currentBuild.changeSets and down. However, I am getting a authorization token missing log-message if I enable the code. This indicates that the problem isn't in calling the functions that tries to reach out to the slack servers, but before that.
I suspect that the way I configured my project, as a pipeline project and that I skip the default checkout is causing this issue. The following code seems suspect to me SlackUserIdResolver.java:
I know for a fact that the changeSets isn't empty when I trigger a build where I'd expect there to be a list of changes here. Not entirely sure how I can make this work.
Anything else?
No response
The text was updated successfully, but these errors were encountered: