jenkinsci / slack-plugin

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

Slack Notification Plugin doesn't seem to use Jenkins' HTTP proxy configuration #978

Open flabrie opened 3 weeks ago

flabrie commented 3 weeks ago

Jenkins and plugins versions report

Environment ```Red hat Enterprise Linux 7 Jenkins 2.461 Slack Notification Plugin 722.vd07f1ea_7ff40 ```

We use the Slack Notification Plugin on several Jenkins service running on different systems (macOS and Linux), using the same configuration. It works without issue on all Jenkins, except the one RHEL 7 server behind an HTTP proxy.

Jenkins is correctly setup with the proxy settings: all other plugins use it without issue.

The *.slack.com domain name it correctly whitelisted by the proxy. We can even test is from the server command line using a curl command line:

$ echo ${https_proxy}
http://142.101.142.12:8080/
$ curl --request POST --data 'payload={"channel": "#tests", "username":  "Jenkins", "text": "This is a test..."}' https://hooks.slack.com/services/${token}
ok

But through Jenkins, we get a Failure message when the Test Connection button is used on the settings, and no notification are received. And we can find a 404 error in Jenkins' log:

Jun 06, 2024 12:34:12 PM FINE jenkins.plugins.slack.StandardSlackService
Posting: to #jenkins on foobar:  {"attachments":[{"fallback":"Slack/Jenkins plugin: you're all set on https://foobar.com/","color":"good","fields":[{"short":false,"value":"Slack/Jenkins plugin: you're all set on https://foobar.com/"}],"mrkdwn_in":["pretext","text","fields"]}],"link_names":"1","unfurl_links":"true","unfurl_media":"true","channel":"#jenkins","username":"Jenkins CLP/CMF"}
Jun 06, 2024 12:34:12 PM WARNING jenkins.plugins.slack.StandardSlackService postToSlack
Slack post may have failed. Response: null
Jun 06, 2024 12:34:12 PM WARNING jenkins.plugins.slack.StandardSlackService postToSlack
Response Code: 404

And as mentioned above, the HTTP proxy settings are correctly set in Jenkins.

What Operating System are you using (both controller, and any agents involved in the problem)?

Red Hat Enterprise Linux 7

Reproduction steps

  1. Open a session on Jenkins
  2. Go to Settings / System
  3. Make sure the HTTP Proxy Configuration section is configured correctly
  4. Go to the Slack section, and fill the required fields to reach your Slack team account
  5. Hit the Test Connection button.

Expected Results

Expecting Slack Notification Plugin to use Jenkins HTTP Proxy Configuration to send messages.

Actual Results

Slack Notification Plugin doesn't seem to reach Slack Services

Anything else?

No response

Are you interested in contributing a fix?

No response

timja commented 3 weeks ago

Can you provide your Slack configuration and how you're sending messages through Jenkins?

I suspect its your slack configuration and not a proxy issue.

flabrie commented 3 weeks ago

Here you'll find the Slack configuration: Capture d’écran, le 2024-06-07 à 08 48 04

I get the failure using the Test Connection button. And here it's a Jenkins job usage example:

Capture d’écran, le 2024-06-07 à 08 51 34

Nothing is set in the Advanced settings.

timja commented 3 weeks ago

Does getting updates for plugins work when you click check for updates? (to verify proxy configuration is right)

timja commented 3 weeks ago

The code path you are going down should be:

https://github.com/jenkinsci/slack-plugin/blob/d07f1ea7ff4009eba4b6dc9ca083feb846beaa8a/src/main/java/jenkins/plugins/slack/StandardSlackService.java#L195

https://github.com/jenkinsci/slack-plugin/blob/d07f1ea7ff4009eba4b6dc9ca083feb846beaa8a/src/main/java/jenkins/plugins/slack/StandardSlackService.java#L480-L484

https://github.com/jenkinsci/slack-plugin/blob/master/src/main/java/jenkins/plugins/slack/HttpClient.java#L38-L51

https://github.com/jenkinsci/slack-plugin/blob/master/src/main/java/jenkins/plugins/slack/StandardSlackService.java#L200

From reading through I can't see anywhere a proxy is missed and I'd expect more people to have issues if so.

flabrie commented 3 weeks ago

Does getting updates for plugins work when you click check for updates? (to verify proxy configuration is right)

Yes, it works. All other plugins requiring to reach an external server uses the proxy successfully. Here is the HTTP proxy configuration:

Capture d’écran, le 2024-06-07 à 08 59 47
flabrie commented 3 weeks ago

The code path you are going down should be:

https://github.com/jenkinsci/slack-plugin/blob/d07f1ea7ff4009eba4b6dc9ca083feb846beaa8a/src/main/java/jenkins/plugins/slack/StandardSlackService.java#L195

https://github.com/jenkinsci/slack-plugin/blob/d07f1ea7ff4009eba4b6dc9ca083feb846beaa8a/src/main/java/jenkins/plugins/slack/StandardSlackService.java#L480-L484

https://github.com/jenkinsci/slack-plugin/blob/master/src/main/java/jenkins/plugins/slack/HttpClient.java#L38-L51

https://github.com/jenkinsci/slack-plugin/blob/master/src/main/java/jenkins/plugins/slack/StandardSlackService.java#L200

From reading through I can't see anywhere a proxy is missed and I'd expect more people to have issues if so.

Yes, I see. Can you tell me what's the hostname the plugin try to reach? Or is it an IP address? Because only *.slack.com domain is whitelisted for this plugin on our proxy.

timja commented 3 weeks ago

for your configuration its coemobile.slack.com

All looks configured right