如何配置jenkins slack插件?

时间:2017-07-29 01:26:25

标签: jenkins jenkins-plugins slack slack-api

我尝试配置jenkins slack插件以向slack通道发送通知。但它不起作用。我按照以下说明操作:

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.

在slack app上安装jenkins后,有一条关于如何配置jenkins的说明。但是指令中提到的配置字段与我的jenkins配置略有不同。

以下是指令的配置截图:

enter image description here

我的jenkins服务器的配置如下所示:

enter image description here

如何在我的配置中填写Base URL?我试图填写我的jenkins url,但它不起作用。测试连接失败。

我在jenkins系统日志中得到以下错误:

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
-->

我试图将基本网址留空但仍然无法正常工作

4 个答案:

答案 0 :(得分:1)

经过大量测试后,我发现了问题。该问题与松弛的配置面板有关。当我更改松弛配置并点击测试按钮时,它不会采用当前配置,而是采用先前保存的配置。我必须首先保存配置然后测试连接。

答案 1 :(得分:0)

不需要填写基本网址。尝试从特定项目。仅在全局设置中提供Team SubDomain 您必须为每个项目单独提供这些信息:

  

团队域/子域
  集成令牌(取自浏览应用程序&gt; Jenkins CI)
  频道名称

对于您希望收到通知的每个项目,请从Jenkins的项目菜单中选择“配置”。

您还需要将Slack Notifications添加到此项目的Post-build Actions中。 在那里提供频道名称,团队子域和集成令牌。 测试连接。

答案 2 :(得分:0)

您可以按项目或每个松弛渠道直接运行POST构建shell脚本



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


其中$ SLACK_WEB_HOOK_URL和$ SLACK_MSG可以作为env变量导出或者为每个项目进行硬编码

答案 3 :(得分:0)

嗨, 您必须将集成令牌添加到Jenkins(我建议添加证书ID,但这不是必需的),这应该是您的问题所在。请记住,您的Jenkins只能将消息发送到渠道,生成令牌的帐户可以访问。

如前所述,您不必添加团队域,并且您的子域必须是Slack链接的以下部分:

www.EXAMPLE.slack.com

希望我能够提供帮助

相关问题