jenkinsci / zulip-plugin

Jenkins plugin for Zulip notifications of build status
https://zulip.com/integrations/doc/jenkins
MIT License
14 stars 22 forks source link

After upgrading Jenkins, the plugin dosen't work anymore #35

Closed eXtrem0us closed 1 year ago

eXtrem0us commented 1 year ago

Jenkins and plugins versions report

Environment ```text Paste the output here ```

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

Jenkins Docker Image. In Version 2.378, everything's fine. But after upgrading to Version 2.383, it breaks. It has been tested on both JDK 11 and JDK 17.

Reproduction steps

Upgrade Jenkins to the latest version.

Expected Results

The message successfully send to Zulip.

Actual Results

The output of Jenkins pipeline, after running zulipSend message: 'some messages here'

java.lang.ClassNotFoundException: org.apache.commons.httpclient.Credentials
    at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:476)
    at jenkins.util.URLClassLoader2.findClass(URLClassLoader2.java:35)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
Caused: java.lang.NoClassDefFoundError: org/apache/commons/httpclient/Credentials
    at jenkins.plugins.zulip.ZulipSendStep.perform(ZulipSendStep.java:44)
    at jenkins.tasks.SimpleBuildStep.perform(SimpleBuildStep.java:123)
    at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:101)
    at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:71)
    at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:829)
[Pipeline] // catchError
[Pipeline] stage
[Pipeline] { (Notify)
[Pipeline] zulipNotification
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
java.lang.ClassNotFoundException: org.apache.commons.httpclient.Credentials
    at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:476)
    at jenkins.util.URLClassLoader2.findClass(URLClassLoader2.java:35)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
Caused: java.lang.NoClassDefFoundError: org/apache/commons/httpclient/Credentials
    at jenkins.plugins.zulip.ZulipNotifier.publish(ZulipNotifier.java:133)
    at jenkins.plugins.zulip.ZulipNotifier.perform(ZulipNotifier.java:86)
    at jenkins.tasks.SimpleBuildStep.perform(SimpleBuildStep.java:123)
    at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:101)
    at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:71)
    at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:829)
Finished: FAILURE

Anything else?

No response

eXtrem0us commented 1 year ago

It seems in the changelog of Jenkins the reason for this issue is mentioned:

What's new in 2.379 (2022-11-22)

Jenkins no longer bundles a patched version of the deprecated Commons HttpClient 3.x library for use by plugins.
Plugins should be migrated to the native Java 11 HTTP client or updated to depend on the legacy Commons HttpClient 3.x API plugin.
timabbott commented 1 year ago

@butchyyyy do you have time to investigate this?

In any case, pull requests are welcome.

butchyyyy commented 1 year ago

Thanks for reporting and apologies for the inconvenience. I'll try to come up with a quick fix this week (adding the commons HttpClient dependency).

xavier-calland commented 1 year ago

FWIW I tried switch to java.net.http client which requires upgrading to java 11+. I had problems with the tests: powermock, mokito, … are not compatible. If you want, I can share my work as WIP.

koval-jan commented 1 year ago

Quick fix is to add pom dependency for plugin commons-httpclient3-api (https://plugins.jenkins.io/commons-httpclient3-api/)

<dependency>
    <groupId>io.jenkins.plugins</groupId>
    <artifactId>commons-httpclient3-api</artifactId>
    <version>3.1-3</version>
</dependency>
EvgenyKuzavlev commented 1 year ago

I tried add а dependency for plugin commons-httpclient3-api to pom. I builded .hpi and tested it in my jenkins server(v. 2.386) and it worked successful, BUT unit-tests were failed. I am going to try fix a problem with tests.

jamesvl commented 1 year ago

This release of Jenkins just hide the wider apt repositories in Ubuntu, so I hit this bug today when I upgraded.

Is there a quick way to fix this locally? I can still in the Commons HttpClient 3.x API Plugin, but that alone doesn't appear sufficient.

EvgenyKuzavlev commented 1 year ago

@jamesvl You can pull my fork and execute mvn hpi:hpi for build a hpi file. After you can manually install it. See https://www.jenkins.io/doc/book/managing/plugins/ for more details.

epaul13 commented 1 year ago

@EvgenyKuzavlev: I used your fork and build it with last maven without problems. After copying the zulip.hpi to plugins/zulip.jpi, the plugin is correctly loaded, but the global configuration and post-build step are not showing up. Any clue?

Note: Maven home: /opt/apache-maven-3.9.1 Java version: 11.0.18, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-openjdk-amd64 Default locale: en, platform encoding: UTF-8 OS name: "linux", version: "5.15.104-1-pve", arch: "amd64", family: "unix"

ipikiiskinen commented 1 year ago

@EvgenyKuzavlev
I also used your fork and build it with:

$ mvn --version Apache Maven 3.9.1 (2e178502fcdbffc201671fb2537d0cb4b4cc58f8) Maven home: /opt/apache-maven-3.9.1 Java version: 11.0.18, vendor: Red Hat, Inc., runtime: /usr/lib/jvm/java-11-openjdk-11.0.18.0.10-1.el7_9.x86_64 Default locale: en_US, platform encoding: UTF-8 OS name: "linux", version: "3.10.0-1160.88.1.el7.x86_64", arch: "amd64", family: "unix" I got the same results as @epaul13 Plugin does not report any error in start up, gets listed as installed plugin, but it does not show in global config or in build definitions. Tested with the latest Jenkins LTS release 2.387.3 (RedHat 7 RPM installation) and openjdk version "11.0.19" 2023-04-18 LTS

@EvgenyKuzavlev Have you managed to the get the plugin working with the latest LTS Jenkins?

ipikiiskinen commented 1 year ago

@butchyyyy you mentioned that you would be looking at this. Any chance to get this fixed?

EvgenyKuzavlev commented 1 year ago

@ipikiiskinen @epaul13 I didn't try to use my fork with latest Jenkins, maybe it doesn't work. I am going to update Jenkins and test it later.

My env: centos-release-7-9.2009.1.el7.centos.x86_64 openjdk 11.0.17 2022-10-18 LTS jenkins 2.386

epaul13 commented 1 year ago

Any news? I can try to make a correction, but my java is rusted, and I don't know maven nor Jenkins dev env... Might not be the most efficient move :)

butchyyyy commented 1 year ago

I have started working on a new major version, it will:

I have bulk of the work done. I just need to adjust the unit tests and give this a proper test flight before shipping the new version. Will keep you posted.

butchyyyy commented 1 year ago

^^ The PR is up, all unit and integration tests are passing.

There are more or less no functional changes besides the http client migration. The rest is mostly formatting stuff and test migration away from Powermock.

I still need to run some manual testing against Jenkins + Zulip before I release this. If anyone has time to also give the branch a quick test and report any issues, it will be much appreciated.

Of course feel free to leave comments on the PR as well, it's first Java code I did in ~4 years 🙈

epaul13 commented 1 year ago

@butchyyyy

I checked out your PR and tested it. I have now access to global configuration and project post-build actions. Great work!

At first, I was unable to get any messages, with an error in Jenkins logs:

011SEVERE#011jenkins.plugins.zulip.Zulip#post: Error sending Zulip message:

sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

I had to add my zulip server chain certificate to make it work. On Ubuntu 22.04, it means:

sudo cp zulip.combined-chain.crt /usr/local/share/ca-certificates
sudo update-ca-certificates
sudo /var/lib/dpkg/info/ca-certificates-java.postinst configure
sudo systemctl restart jenkins

Now I get my jenkins post messages from Jenkins! Thank you again!

So this work on Jenkins 2.387.3 on java 11.0.18 on Ubuntu 22.04


To build, for maven/jenkins devenv noobs like me:

git clone https://github.com/jenkinsci/zulip-plugin.git                                                                                                                                
cd zulip-plugin/
git checkout origin/version2
mvn package
# uninstall previous zulip plugin
sudo -u jenkins cp target/zulip.hpi /var/lib/jenkins/plugins/
sudo systemctl restart jenkins

with:

mvn --version
Apache Maven 3.9.1 (2e178502fcdbffc201671fb2537d0cb4b4cc58f8)
Maven home: /opt/apache-maven-3.9.1
Java version: 11.0.18, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en, platform encoding: UTF-8
OS name: "linux", version: "5.15.104-1-pve", arch: "amd64", family: "unix"
butchyyyy commented 1 year ago

Thanks a lot for testing it @epaul13! The certificate chain validation is correct and afaik it was performed also with the Apache http client. Let me know if you think this is behaving differently than before.

I was also testing on my end today and verified several scenarios including proxy being setup in Jenkins both with and without authentication.

I think we are good to go, will most probably do the release tomorrow.

butchyyyy commented 1 year ago

Resolved in version 2.0.0

epaul13 commented 1 year ago

Thanks a lot for testing it @epaul13! The certificate chain validation is correct and afaik it was performed also with the Apache http client. Let me know if you think this is behaving differently than before.

I was also testing on my end today and verified several scenarios including proxy being setup in Jenkins both with and without authentication.

I think we are good to go, will most probably do the release tomorrow.

Good news. For the certificate validation, my bad. I tested on a brand-new container, and my old jenkins is probably ten years old. I just checked and I have the same chain on the old server. So everything' good!

eXtrem0us commented 1 year ago

Thank You @butchyyyy ! :heart: