How to get Slack notification from Jenkins on creating a new job?

Viewed 118

I have a Jenkins instance with a bunch of jobs in it. This is shared across developers at the company. Our team would like to be notified whenever someone creates a new job on this instance.

Googling this is so difficult because I'm not looking for information on a specific job, I want an instance-wide hook that alerts Slack when a new job is created on it.

Is this possible? Maybe through a plugin? Or buried in the settings somewhere?

1 Answers

One possibly solution to my own problem is this: https://support.cloudbees.com/hc/en-us/articles/226941767-Groovy-to-list-all-jobs#resolution

Something like this specifically in a "execute system Groovy script" block

import jenkins.model.Jenkins
import hudson.model.*

// This script will print the name of all jobs including jobs inside of a folder, but not the folders themselves
Jenkins.instance.getAllItems(Job.class).each{ 
    println it.name + " - " + it.class
}

Then do an alert based on those results.

Related