Prefix
(Lukas)
February 17, 2025, 11:38am
1
Hello.
I’m using latest jenkins and latest o365 connector plugin (GitHub - jenkinsci/office-365-connector-plugin: Office 365 Connector plugin sends jobs status notifications to Microsoft Teams or Outlook )
It has some global settings
but I have over 150 jobs and I want them to be visible via connector. Is there some script possibility to enable for them all at once this plugin?
Also for some reason I see only build start, it doesn’t send like this Started → Successful build or Started → Build failure?
Prefix
(Lukas)
February 17, 2025, 2:16pm
2
ok found a way, maybe someone else will need it
import jenkins.model.Jenkins
import hudson.model.AbstractProject
import jenkins.plugins.office365connector.WebhookJobProperty
import jenkins.plugins.office365connector.Webhook
// Iterate over all jobs that are a subclass of AbstractProject
Jenkins.instance.getAllItems(Job.class).each { job ->
if (job.getProperty(WebhookJobProperty)) {
job.removeProperty(WebhookJobProperty)
println "Removed existing Office 365 Connector property from job: ${job.fullName}"
}
def webhook = new Webhook("Jenkins Webhook")
// Set the remaining properties via setters (or direct property assignment)
webhook.url = "webhookurl"
webhook.startNotification = true
webhook.notifySuccess = true
webhook.notifyAborted = true
webhook.notifyNotBuilt = false
webhook.notifyUnstable = true
webhook.notifyFailure = true
webhook.notifyBackToNormal = true
webhook.notifyRepeatedFailure = false
webhook.timeout = 30000
webhook.adaptiveCards = true
webhook.factDefinitions = [] // empty list
webhook.macros = [] // empty list
// Create and add the property to the job
job.addProperty(new WebhookJobProperty([webhook]))
job.save()
println "Added Office 365 Connector property to job: ${job.fullName}"
}