Jenkins JobDSL for Office365 Connector

Jenkins JobDSL for Office365 Connector

Once you get your Office 365 web-hook for the Jenkins Connector you can use the configure block below to add it to your different jobs. Let’s say we have a simple freeStyleJob like.

import Common

job = freeStyleJob(some) {
    label('my-label')
    scm {
        git {
            remote {
                name('origin')
                url(gitUrl)
            }
            branches('master')
            extensions {}
        }
    }
    triggers {
        githubPush()
    }
    steps {
       shell(commandLine)
    }
}

Common.addTeams(job)

We could then create a function addTeams and accept a job and put in a reusable class.

class Common {
    static void addTeams(Job job) {
            job.with {
                configure {
                    project ->
                    def office365 = project / 'properties' / 'jenkins.plugins.office365connector.WebhookJobProperty'(plugin: 'Office-365-Connector@4.6.0') {
                        webhooks {
                           'jenkins.plugins.office365connector.Webhook' {
                                name('cpcsa-bento')
                                url('https://outlook.office.com/webhook/......')
                                notifyAborted(true)
                                notifyFailure(true)
                                notifyNotBuilt(true)
                                notifyUnstable(true)
                                notifyBackToNormal(true)
                                notifySuccess(false)
                                notifyRepeatedFailure(false)
                                startNotification(false)
                                timeout(30000)
                            }
                        }
                    }
                }
            }
        }
    }