Skip to content
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

Omitting room from Slack JCasC configuration leads to "java.lang.IllegalArgumentException: Project Channel or Slack User ID must be specified." #857

Open
jlebon opened this issue Nov 16, 2022 · 7 comments
Labels

Comments

@jlebon
Copy link

jlebon commented Nov 16, 2022

Jenkins and plugins versions report

Environment
Jenkins: 2.319.3
OS: Linux - 4.18.0-372.26.1.el8_6.x86_64
---
ace-editor:1.1
ant:1.11
antisamy-markup-formatter:2.7
apache-httpcomponents-client-4-api:4.5.13-1.0
authentication-tokens:1.4
basic-branch-build-strategies:1.3.2
blueocean:1.24.8
blueocean-autofavorite:1.2.4
blueocean-bitbucket-pipeline:1.24.8
blueocean-commons:1.24.8
blueocean-config:1.24.8
blueocean-core-js:1.24.8
blueocean-dashboard:1.24.8
blueocean-display-url:2.4.1
blueocean-events:1.24.8
blueocean-git-pipeline:1.24.8
blueocean-github-pipeline:1.24.8
blueocean-i18n:1.24.8
blueocean-jwt:1.24.8
blueocean-personalization:1.24.8
blueocean-pipeline-api-impl:1.24.8
blueocean-pipeline-editor:1.24.8
blueocean-pipeline-scm-api:1.24.8
blueocean-rest:1.24.8
blueocean-rest-impl:1.24.8
blueocean-web:1.24.8
bootstrap4-api:4.6.0-3
bouncycastle-api:2.25
branch-api:2.1044.v2c007e51b_87f
caffeine-api:2.9.3-65.v6a_47d0f4d1fe
checks-api:1.7.2
cloudbees-bitbucket-branch-source:2.4.4
cloudbees-folder:6.714.v79e858ef76a_2
command-launcher:1.2
conditional-buildstep:1.4.1
config-file-provider:3.8.1
configuration-as-code:1.55.1
configuration-as-code-groovy:1.1
credentials:2.6.1.1
credentials-binding:1.27.1
display-url-api:2.3.5
docker-commons:1.18
durable-task:493.v195aefbb0ff2
echarts-api:5.0.2-1
favorite:2.4.1
font-awesome-api:5.15.2-2
generic-webhook-trigger:1.84.2
git:4.11.3
git-client:3.11.0
git-server:1.10
github:1.34.1
github-api:1.303-400.v35c2d8258028
github-branch-source:2.11.4
github-oauth:0.39
google-oauth-plugin:1.0.6
groovy:2.4
handy-uri-templates-2-api:2.1.6-1.0
htmlpublisher:1.25
jackson2-api:2.13.3-285.vc03c0256d517
javadoc:1.0
javax-activation-api:1.2.0-3
javax-mail-api:1.6.2-2
jaxb:2.3.6-1
jdk-tool:1.0
jenkins-design-language:1.24.8
jira:3.7.1
jjwt-api:0.11.2-5.143e44951c52
job-dsl:1.77
jquery3-api:3.6.0-1
jsch:0.1.55.2
junit:1.53
kubernetes:1.31.2
kubernetes-client-api:5.12.1-187.v577c3e368fb_6
kubernetes-credentials:0.9.0
kubernetes-credentials-provider:1.199.v4a_1d1f5d074f
lockable-resources:2.11
mailer:414.vcc4c33714601
mapdb-api:1.0.9.0
matrix-auth:2.6.8
matrix-project:771.v574584b_39e60
maven-plugin:3.7
mercurial:2.15
metrics:4.0.2.8
oauth-credentials:0.4
okhttp-api:4.9.2-20211102
openshift-client:1.0.35
openshift-login:1.0.26
openshift-sync:1.0.53
pam-auth:1.6
parameterized-trigger:2.43.1
pipeline-build-step:2.16
pipeline-github:2.8-138.d766e30bb08b
pipeline-graph-analysis:1.10
pipeline-input-step:2.12
pipeline-milestone-step:1.3.1
pipeline-model-api:1.9.3
pipeline-model-definition:1.8.4
pipeline-model-extensions:1.9.3
pipeline-rest-api:2.15
pipeline-stage-step:2.5
pipeline-stage-tags-metadata:1.8.4
pipeline-utility-steps:2.12.0
plain-credentials:1.7
plugin-util-api:2.4.0
popper-api:1.16.1-2
prometheus:2.0.10
pubsub-light:1.13
run-condition:1.3
scm-api:602.v6a_81757a_31d2
script-security:1138.v8e727069a_025
slack:625.va_eeb_b_168ffb_0
snakeyaml-api:1.29.1
sse-gateway:1.24
ssh-credentials:1.19
sshd:3.0.4
structs:308.v852b473a2b8c
subversion:2.15.4
timestamper:1.20
token-macro:293.v283932a_0a_b_49
trilead-api:1.0.13
variant:1.4
windows-slaves:1.0
workflow-api:1153.vb_912c0e47fb_a_
workflow-basic-steps:2.20
workflow-cps:2660.vb_c0412dc4e6d
workflow-cps-global-lib:566.vd0a_a_3334a_555
workflow-durable-task-step:2.35
workflow-job:1145.v7f2433caa07f
workflow-multibranch:716.vc692a_e52371b_
workflow-scm-step:2.13
workflow-step-api:625.vd896b_f445a_f8
workflow-support:813.vb_d7c3d2984a_0

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

Jenkins running on OpenShift Container Platform 4.11.

Reproduction steps

  1. Configure Slack using JCasC. Omit the room key. E.g. the minimal config would be:
unclassified:
  slackNotifier:
    teamDomain: mydomain
    tokenCredentialId: slack-api-token
  1. Bring up a new Jenkins with this JCasC config
  2. Try to use slackSend from a pipeline without specifying a channel

Expected Results

Slack message goes to default channel associated with token.

Actual Results

23:17:50  java.lang.IllegalArgumentException: Project Channel or Slack User ID must be specified.
23:17:50  	at jenkins.plugins.slack.StandardSlackService.<init>(StandardSlackService.java:140)
23:17:50  	at jenkins.plugins.slack.workflow.SlackSendStep$SlackSendStepExecution.getSlackService(SlackSendStep.java:451)
23:17:50  	at jenkins.plugins.slack.workflow.SlackSendStep$SlackSendStepExecution.run(SlackSendStep.java:307)
23:17:50  	at jenkins.plugins.slack.workflow.SlackSendStep$SlackSendStepExecution.run(SlackSendStep.java:258)
23:17:50  	at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)
23:17:50  	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
23:17:50  	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
23:17:50  	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
23:17:50  	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
23:17:50  	at java.base/java.lang.Thread.run(Thread.java:829)
23:17:50  Finished: FAILURE

Anything else?

It appears that this is fixed by just adding room: "" to the JCasC config. Another way to work around this is to go to the Jenkins configuration page and just save it without changing anything; an empty room tag will be added to the Slack config on-disk.

So it sounds like there might be faulty logic somewhere that distinguishes between a null vs empty string for the room when it shouldn't.

@jlebon jlebon added the bug label Nov 16, 2022
jlebon added a commit to jlebon/fedora-coreos-pipeline that referenced this issue Nov 16, 2022
After 27693a6, the Slack plugin fails to send messages on new Jenkins instances with:

    java.lang.IllegalArgumentException: Project Channel or Slack User ID
    must be specified.

This seems to be due to some bug in the plugin where without a `room`
setting, it doesn't know to rely on the default room associated with the
token. This is filed upstream in:

jenkinsci/slack-plugin#857

Short-term, let's just work around this by specifying an empty `room`.
dustymabe pushed a commit to coreos/fedora-coreos-pipeline that referenced this issue Nov 16, 2022
After 27693a6, the Slack plugin fails to send messages on new Jenkins instances with:

    java.lang.IllegalArgumentException: Project Channel or Slack User ID
    must be specified.

This seems to be due to some bug in the plugin where without a `room`
setting, it doesn't know to rely on the default room associated with the
token. This is filed upstream in:

jenkinsci/slack-plugin#857

Short-term, let's just work around this by specifying an empty `room`.
@timja
Copy link
Member

timja commented Nov 17, 2022

Is there a reason you aren’t specifying a room?

While web hooks do work some functionality won’t work with them.

@jlebon
Copy link
Author

jlebon commented Nov 17, 2022

We use the same JCasC config to bring up multiple instances of Jenkins for different pipelines. They each send notifications to different Slack rooms and have their own separate tokens. We've been able to avoid having to conditionalize/templatize JCasC configs so far to keep things simple. Everything seems to work, so we're not using any functionality of slackSend that explicitly requires a room.

@timja
Copy link
Member

timja commented Nov 18, 2022

but you can just create one bot user, and one token. invite the bot to the room and then override the room as you need it. a room in your slack send config is a lot clearer than a token

@jlebon
Copy link
Author

jlebon commented Nov 18, 2022

We're trying to avoid adding more configuration than needed to differentiate between the pipelines. It's really nice right now that we don't have to specify the room each time we slackSend and it does the right thing. Is that by design or just a happy accident?

@timja
Copy link
Member

timja commented Nov 18, 2022

it's accidental, and as far as I know the webhooks you are using are likely deprecated:
https://api.slack.com/legacy/custom-integrations/messaging/webhooks#migrating-from-legacy

don't you currently need to provide configuration to override the token? or are you doing that at a folder level?

@jlebon
Copy link
Author

jlebon commented Nov 18, 2022

it's accidental

Ahh, that's unfortunate. In that case we'll have to throw more configuration at it. It's confusing though, because when you set this up on the Slack app side, it asks for a channel to post to. Is there any purpose to that?

and as far as I know the webhooks you are using are likely deprecated: api.slack.com/legacy/custom-integrations/messaging/webhooks#migrating-from-legacy

We're using the Jenkins CI app in Slack and get the token it generates from there. Is that using the legacy webhooks API?

don't you currently need to provide configuration to override the token? or are you doing that at a folder level?

The Jenkins credential is named the same (so is embedded in the generic JCasC dropin), but it's created differently per-pipeline.

@timja
Copy link
Member

timja commented Nov 18, 2022

no that's not the webhooks one that's the legacy slack built-in one.
see more here:
https://github.com/jenkinsci/slack-plugin#bot-user-mode

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants