简体   繁体   English

如何配置 jenkins slack 插件?

[英]How to configure jenkins slack plugin?

I tried to configure jenkins slack plugin to send a notification to slack channel.我尝试配置 jenkins slack 插件以向 slack 通道发送通知。 But it doesn't work.但它不起作用。 I followed below instruction:我遵循以下说明:

1. Get a Slack account: https://slack.com/
2. Configure the Jenkins integration: https://my.slack.com/services/new/jenkins-ci
3. Install this plugin on your Jenkins server.
4. Configure it in your Jenkins job (and optionally as global configuration) and add it as a Post-build action.

After I install jenkins on slack app there is a instruction about how to configure jenkins.在我在 slack app 上安装jenkins之后,有一个关于如何配置 jenkins 的说明。 But the configuration fields mentioned on the instruction is a little different than my jenkins configuration.但是说明中提到的配置字段与我的 jenkins 配置略有不同。

Below is the configuration screenshot from the instruction:以下是说明中的配置屏幕截图:

在此处输入图像描述

the configuration for my jenkins server looks like below:我的詹金斯服务器的配置如下所示:

在此处输入图像描述

how can I fill in the Base URL in my configuration?如何在我的配置中填写Base URL I have tried to fill in my jenkins url but it doesn't work.我试图填写我的jenkins url ,但它不起作用。 The test connection failed.测试连接失败。

I get below error in jenkins system log:我在詹金斯系统日志中收到以下错误:

Slack post may have failed. Response: <html><head><meta http-equiv='refresh' content='1;url=/login?from=%2FOPRc9G4zB2JX289VOnTvfeey'/><script>window.location.replace('/login?from=%2FOPRc9G4zB2JX289VOnTvfeey');</script></head><body style='background-color:white; color:white;'>


Authentication required
<!--
You are authenticated as: anonymous
Groups that you are in:

Permission you need to have (but didn't): hudson.model.Hudson.Read
 ... which is implied by: hudson.security.Permission.GenericRead
 ... which is implied by: hudson.model.Hudson.Administer
-->

I have tried to leave base url empty but still doesn't work我试图将基本网址留空但仍然无效

After a lot of testing, I figured out the problem.经过大量测试,我发现了问题所在。 The issue relates to the configuration panel for slack.该问题与 slack 的配置面板有关。 When I change the slack configuration and hit the test button, it doesn't take the current configuration, instead, it takes the previously saved configuration.当我更改松弛配置并点击测试按钮时,它不会采用当前配置,而是采用以前保存的配置。 I have to save the configuration first then test the connection.我必须先保存配置然后测试连接。

Base URL doesn't need to be filled.基本 URL 不需要填写。 Try from Specific Project.从特定项目尝试。 Only supply Team SubDomain in Global setting.仅在全局设置中提供团队子域。
You have to provide these info separately for every project:您必须为每个项目单独提供这些信息:

Team Domain/Sub-Domain团队域/子域
Integration Token(Taken from the Browse Apps > Jenkins CI)集成令牌(取自 Browse Apps > Jenkins CI)
Channel Name频道名称

For each Project that you would like receive notifications for, choose Configure from the project's menu in Jenkins.对于您希望收到通知的每个项目,从 Jenkins 的项目菜单中选择配置。

You'll also need to add Slack Notifications to the Post-build Actions for this project.您还需要将 Slack 通知添加到此项目的构建后操作。 Provide the Channel name, Team Subdomain and Integration Token there.在那里提供频道名称、团队子域和集成令牌。 Test the connection.测试连接。

you can directly run a POST build shell script per project basis or per slack channel您可以针对每个项目或每个松弛通道直接运行 POST 构建 shell 脚本



#!/bin/bash
curl -X POST --data-urlencode 'payload={"text": "'"$SLACK_MSG"'"}' $SLACK_WEB_HOOK_URL


where $SLACK_WEB_HOOK_URL and $SLACK_MSG can be exported as env variables or hardcode it for each project其中 $SLACK_WEB_HOOK_URL 和 $SLACK_MSG 可以导出为环境变量或为每个项目对其进行硬编码

Hay, you have to add you integration Token to your Jenkins(I would recommend to add a Credential ID but its not necessary), that should sole your Problem.嘿,你必须将你的集成令牌添加到你的 Jenkins(我建议添加一个凭据 ID 但它不是必需的),这应该解决你的问题。 Keep in mind that your Jenkins just can send Messages to channels, the Account which generated the token has access to.请记住,您的 Jenkins 只能将消息发送到通道,生成令牌的帐户可以访问。

As said previously, you dont have to add a Team-Domain and your Subdomain has to be the following part of your Slack link:如前所述,您不必添加团队域,您的子域必须是 Slack 链接的以下部分:

www.EXAMPLE.slack.com www.EXAMPLE.slack.com

Hopefully i was able to help希望我能帮上忙

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM