Skip to content

A Python/Flask service to allow Jenkins to send desktop notifications

License

Notifications You must be signed in to change notification settings

oranja/NotificationBridge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NotifyBridge

Introduction

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.

Usage

For one-time usage, configure Jenkins as described in steps 6-7 below and run the script:

$ python3 NotifyBridge.py

Exit the script by pressing Ctrl+C in the console it's running at.

Installation

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.

Tested and built for

Requirements

Steps

  1. Install dependencies:
$ sudo dnf install python3-flask python3-gobject
$ sudo pip3 install Flask-JSON
  1. Copy the NotifyBridge.py script 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.py
  1. Copy the NotifyBridge@.service systemd unit file to /usr/lib/systemd/user/ (you'll need root permissions).

  2. Add the following content to the end of your ~/.profile file.

systemctl --user import-environment DBUS_SESSION_BUS_ADDRESS
systemctl --user import-environment DISPLAY
systemctl --user start NotifyBridge@${USER}.service

Note: Also run these 3 commands now to start the service now (without restarting the session).

  1. From the Jenkins dashboard, install the Notification Plugin. Restart Jenkins as required.

  2. 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

Uninstallation

  1. Stop the service:
$ systemctl --user stop NotifyBridge@${USER}.service
  1. Remove the script and unit file:
$ sudo rm /usr/local/bin/NotifyBridge.py
$ sudo rm /usr/lib/systemd/user/NotifyBridge@.service
  1. Remove these lines from your ~/.profile:
systemctl --user import-environment DBUS_SESSION_BUS_ADDRESS
systemctl --user import-environment DISPLAY
systemctl --user start NotifyBridge@${USER}.service

Troubleshooting

If 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.py

If this works but running as a service fails, try investigating whatever issue you're having by using:

$ systemctl --user status NotifyBridge@${USER}.service

and

$ journalctl --user

License

This 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)

About

A Python/Flask service to allow Jenkins to send desktop notifications

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages