Jenkins notifications in per job slack channel

Yesterday evening, an overhaul of how slack notifications of jenkins’ builds are handled was deployed. The main goals were to:

  • reduce the amount of noise that developers were being exposed to in #dm-jenkins
  • empower developers with fine grain control to monitor or ignore activity on a per job basis
  • improve the format of notifications messages and include user submitted build parameters
  • automatically ‘invite’ developers into notification channels as a ‘discovery mechanism’

Virtually all jenkins jobs will now send build notification messages to a slack channel with a named based on the jenkins job name. These channels are created on demand as builds are submitted. Slack users with a correct github username set on their profile will automatically be ‘invited’ into the notification channel for a job upon submitting a build.

Developers are also able to monitor arbitrary jobs, such as the various ‘cron’ triggered daily builds. Eg., science-pipelines/lsst_build by manually joining the associated channel.

As slack channel names have a hard limit of of 22 characters (including the # prefix), and do not allow most punctuation, an unfortunate level of mangling of the jenkins job name is required to work within the slack channel name constraints. The current scheme is:

  • all channels are prefixed with #dmj-, as in “DM Jenkins”
  • /s in jenkins folder paths are transliterated into _s
  • jenkins folder path components are each truncated to the first character
  • the ‘base’ name of the job is kept verbatim if it will fit within the character limit, otherwise the job name is truncated to fit. If there are -s in the name, each ‘word’ separated by a - is truncated

Eg. science-pipelines/lsst_build -> #dmj-s_lsst_build

The fully qualified name of the job, along with a link to the jenkins job, is set as the topic of the channel. Unfortunately, the slack channel search functionality only matches on the literal name of the job. The current recommendation for identifying the channel associated with a job is to search for #dmj- and scroll through the listing. The complete jenkins job is also set in the channel’s ‘purpose’ string, which is displayed in search results.

Jenkins notifications may be controlled on a per job basis by using slack’s “Notification Preferences”. The dialogs will vary by the slack client being used. Essentially, a job may be “subscribed” to by selecting notification of “All new messages” and “unsubscribed” from by mute the entire channel.

Per client configuration is well covered in the official Guide to Slack notifications


1 Like