I have been looking for a way to let Jenkins deliver pop-up notifications to my KDE desktop sessions. The Hudson Tray Application doesn't seem to be truly KDE-compatible. Previous attempts with alternative approaches failed, stemming mostly from the fact the Jenkins runs under a special jenkins user on the system. export-ing DBUS_SESSION_BUS_ADDRESS and DISPLAY allowed neither Groovy nor shell scripts running under jenkins to reach my desktop DBus session.
Eventually, the solution I chose is a simple Python script combined with Jenkins' Notification Plugin.
It is provided here for your own convenience and as a request for further improvement.
For one-time usage, configure Jenkins as described in steps 6-7 below and run the script:
$ python3 NotifyBridge.pyExit the script by pressing Ctrl+C in the console it's running at.
Installation can be mostly automated, but for now, you'll have to do things yourself and perhaps fiddle with things a bit until everything runs together.
- Jenkins
- Python 3+
- Flask(for a quick RESTful web application)
- Flask-JSON(for easy JSON-based request/response format)
- python3-gobject(for libnotify integration)
- libnotify(for sending notificiations to KDE)
- Install dependencies:
$ sudo dnf install python3-flask python3-gobject
$ sudo pip3 install Flask-JSON- Copy the
NotifyBridge.pyscript to/usr/local/bin/or similiar (you'll need root permissions).
Make sure it has proper access rights.
chmod a+x /usr/local/bin/NotifyBridge.pyCopy the
NotifyBridge@.servicesystemd unit file to/usr/lib/systemd/user/(you'll need root permissions).Add the following content to the end of your
~/.profilefile.
systemctl --user import-environment DBUS_SESSION_BUS_ADDRESS
systemctl --user import-environment DISPLAY
systemctl --user start NotifyBridge@${USER}.serviceNote: Also run these 3 commands now to start the service now (without restarting the session).
From the Jenkins dashboard, install the Notification Plugin. Restart Jenkins as required.
For each Jenkins job you want to get notifications for, Configure the job, such that under Job Notifications you will have two endpoints:
| Field | Value |
|---|---|
| Format | JSON |
| Protocl | HTTP |
| Event | Job Started |
| URL | http://localhost:29876/notify/jenkins/build/start |
| Field | Value |
|---|---|
| Format | JSON |
| Protocl | HTTP |
| Event | Job Finalized |
| URL | http://localhost:29876/notify/jenkins/build/result |
- Stop the service:
$ systemctl --user stop NotifyBridge@${USER}.service- Remove the script and unit file:
$ sudo rm /usr/local/bin/NotifyBridge.py
$ sudo rm /usr/lib/systemd/user/NotifyBridge@.service- Remove these lines from your
~/.profile:
systemctl --user import-environment DBUS_SESSION_BUS_ADDRESS
systemctl --user import-environment DISPLAY
systemctl --user start NotifyBridge@${USER}.serviceIf something goes wrong, I'm personally sorry, but well, it was predictable. Maybe inevitable.
First, I suggest that you try running the script as a stand-alone and watch the console's output.
$ python3 NotifyBridge.pyIf this works but running as a service fails, try investigating whatever issue you're having by using:
$ systemctl --user status NotifyBridge@${USER}.serviceand
$ journalctl --userThis software is released as a free and open source software under GNU/LGPLv3.
Summary and full text can be found here:
https://tldrlegal.com/license/gnu-lesser-general-public-license-v3-(lgpl-3)