jenkinsci / discord-notifier-plugin

A post-build plugin that sends the build status to a Discord channel.
https://plugins.jenkins.io/discord-notifier/
MIT License
50 stars 25 forks source link

NPE preventing successful build notification #53

Closed nbelisle11 closed 2 years ago

nbelisle11 commented 2 years ago

Jenkins and plugins versions report

Environment ```text Jenkins: 2.319.2 OS: Windows 10 - 10.0 --- ace-editor:1.1 antisamy-markup-formatter:2.7 apache-httpcomponents-client-4-api:4.5.13-1.0 bootstrap4-api:4.6.0-3 bootstrap5-api:5.1.3-4 bouncycastle-api:2.25 branch-api:2.7.0 build-timeout:1.20 caffeine-api:2.9.2-29.v717aac953ff3 checks-api:1.7.2 cloudbees-folder:6.17 command-launcher:1.6 conditional-buildstep:1.4.1 credentials:1074.v60e6c29b_b_44b_ credentials-binding:1.27.1 dashboard-view:2.18 discord-notifier:205.v893fce17f6cd display-url-api:2.3.5 durable-task:493.v195aefbb0ff2 echarts-api:5.2.2-2 external-monitor-job:191.v363d0d1efdf8 font-awesome-api:5.15.4-5 git:4.10.3 git-client:3.11.0 git-server:1.10 github:1.34.1 github-api:1.301-378.v9807bd746da5 github-branch-source:2.11.4 handlebars:3.0.8 jackson2-api:2.13.1-246.va8a9f3eaf46a javadoc:1.6 javax-activation-api:1.2.0-2 javax-mail-api:1.6.2-5 jaxb:2.3.0.1 jdk-tool:1.5 jjwt-api:0.11.2-9.c8b45b8bb173 jnr-posix-api:3.1.7-1 jquery-detached:1.2.1 jquery3-api:3.6.0-2 jsch:0.1.55.2 junit:1.53 ldap:2.7 lockable-resources:2.13 log-parser:2.2 mailer:408.vd726a_1130320 matrix-auth:3.0.1 matrix-project:1.20 maven-plugin:3.16 momentjs:1.1.1 okhttp-api:4.9.3-105.vb96869f8ac3a pam-auth:1.7 pipeline-build-step:2.15 pipeline-github-lib:36.v4c01db_ca_ed16 pipeline-graph-analysis:188.v3a01e7973f2c pipeline-input-step:446.vf27b_0b_83500e pipeline-milestone-step:1.3.2 pipeline-model-api:1.9.3 pipeline-model-definition:1.9.3 pipeline-model-extensions:1.9.3 pipeline-rest-api:2.21 pipeline-stage-step:291.vf0a8a7aeeb50 pipeline-stage-tags-metadata:1.9.3 pipeline-stage-view:2.21 plain-credentials:1.8 plugin-util-api:2.13.0 popper-api:1.16.1-2 popper2-api:2.11.2-1 preSCMbuildstep:0.3 publish-over:0.22 publish-over-dropbox:1.3.2 resource-disposer:0.17 run-condition:1.5 scm-api:595.vd5a_df5eb_0e39 script-security:1131.v8b_b_5eda_c328e snakeyaml-api:1.29.1 ssh-credentials:1.19 ssh-slaves:1.33.0 sshd:3.1.0 structs:308.v852b473a2b8c timestamper:1.17 token-macro:267.vcdaea6462991 trilead-api:1.0.13 unity3d-plugin:1.3 windows-slaves:1.8 workflow-aggregator:2.6 workflow-api:1136.v7f5f1759dc16 workflow-basic-steps:2.24 workflow-cps:2648.va9433432b33c workflow-cps-global-lib:552.vd9cc05b8a2e1 workflow-durable-task-step:1121.va_65b_d2701486 workflow-job:1145.v7f2433caa07f workflow-multibranch:706.vd43c65dec013 workflow-scm-step:2.13 workflow-step-api:622.vb_8e7c15b_c95a_ workflow-support:813.vb_d7c3d2984a_0 ws-cleanup:0.40 ```

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

OS: Windows 10 - 10.0

Reproduction steps

image With this configuration I get a proper notification when the build starts and I never get a notification when the build ends. There's a NPE in the logs when the notification should be sent upon build completion.

Expected Results

I expected the Discord notification to be sent without exception.

Actual Results

10:37:21 ERROR: Build step failed with exception
10:37:21 java.lang.NullPointerException
10:37:21    at java.base/java.util.regex.Matcher.getTextLength(Matcher.java:1770)
10:37:21    at java.base/java.util.regex.Matcher.reset(Matcher.java:416)
10:37:21    at java.base/java.util.regex.Matcher.<init>(Matcher.java:253)
10:37:21    at java.base/java.util.regex.Pattern.matcher(Pattern.java:1133)
10:37:21    at java.base/java.util.Formatter.parse(Formatter.java:2700)
10:37:21    at java.base/java.util.Formatter.format(Formatter.java:2655)
10:37:21    at java.base/java.util.Formatter.format(Formatter.java:2609)
10:37:21    at java.base/java.lang.String.format(String.java:2897)
10:37:21    at nz.co.jammehcow.jenkinsdiscord.util.EmbedDescription.<init>(EmbedDescription.java:50)
10:37:21    at nz.co.jammehcow.jenkinsdiscord.WebhookPublisher.perform(WebhookPublisher.java:300)
10:37:21    at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
10:37:21    at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:806)
10:37:21    at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:755)
10:37:21    at hudson.model.Build$BuildExecution.cleanUp(Build.java:188)
10:37:21    at hudson.model.Run.execute(Run.java:1935)
10:37:21    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
10:37:21    at hudson.model.ResourceController.execute(ResourceController.java:99)
10:37:21    at hudson.model.Executor.run(Executor.java:432)
10:37:21 Build step 'Discord Notifier' marked build as failure
10:37:21 Finished: SUCCESS

Anything else?

No response

nbelisle11 commented 2 years ago

I've confirmed that removing the Title and the Branch name from that config fixes this issue for us.

BillyGalbreath commented 2 years ago

I believe I located the root cause. I was running into the same issue except my Title and Branch name are already blank. So I checked and I see that scmWebUrl is null on line 50. So I hunted down what this value is, and turns out it's the Repository Browser under the Source Code Management section of the job. Mine was set to auto, so I manually filled it out and it works fine now. So I'm assuming auto doesn't properly detect the url.

Edit: Well, that was short lived. Getting an NPE again, this time without a stacktrace pointing to the cause. I'm just going to fork and revert that Linkify commit.

00bins commented 2 years ago

This is the same issue that I reported (as a comment) here https://github.com/jenkinsci/discord-notifier-plugin/pull/34#issuecomment-1033103790

I fixed it for me catching NPE in that try/catch block

KocproZ commented 2 years ago

Please check if #55 fixed the issue for You