Office 365 Connector plugin for Jenkins
Plugin is used to send actionable messages in Outlook, Office 365 Groups, and Microsoft Teams.
- Install this plugin on your Jenkins server
- Configure it in your Jenkins job and add webhook URL obtained from office 365 connector.
The plugin can also be configured through global settings under Jenkins -> Manage Jenkins -> Configure System. The values in the global settings will be used as default when using the plugin for a job. These settings can then be overridden in the job. Changing the values in the global settings will however not update any settings in an existing job.
job('Example Job Name') {
description 'Example description'
properties {
office365ConnectorWebhooks {
webhooks {
webhook {
name('Example Webhook Name')
url('https://outlook.office.com/webhook/123456...')
startNotification(false)
notifySuccess(true)
notifyAborted(false)
notifyNotBuilt(false)
notifyUnstable(true)
notifyFailure(true)
notifyBackToNormal(true)
notifyRepeatedFailure(false)
timeout(30000)
}
}
}
}
// Webhook Macro Configuration
configure {
// Example: Conditioning webhook trigger on build parameter 'version' being equal to 'latest'
// Templates are defined as token macros https://github.com/jenkinsci/token-macro-plugin
it / 'properties' / 'jenkins.plugins.office365connector.WebhookJobProperty' / 'webhooks' / 'jenkins.plugins.office365connector.Webhook' / 'macros' << 'jenkins.plugins.office365connector.model.Macro' {
template('${ENV, var="version"}')
value('latest')
}
}
}
pipeline('Example Job Name'){
// configure office365connector plugin using DSL configure for flow-definition
configure { project ->
project / 'properties' << 'jenkins.plugins.office365connector.WebhookJobProperty' {
webhooks {
'jenkins.plugins.office365connector.Webhook' {
name("Office 365 Team channel notifications")
url("${Your webhook URL that needs to configure ( teams channel / outlook )}")
startNotification(false)
notifySuccess(false)
notifyAborted(false)
notifyNotBuilt(false)
notifyUnstable(false)
notifyFailure(true)
notifyBackToNormal(false)
notifyRepeatedFailure(false)
timeout(30000)
}
}
}
}
}
pipeline {
agent any
options {
office365ConnectorWebhooks([[
name: 'Office 365',
startNotification: true,
url: 'https://outlook.office.com/webhook/123456...'
]])
}
stages {
stage('Init') {
steps {
echo 'Starting!'
}
}
}
}
stage('Upload') {
steps {
// some instructions here
office365ConnectorSend webhookUrl: 'https://outlook.office.com/webhook/123456...',
message: 'Application has been [deployed](https://uat.green.biz)',
status: 'Success'
}
}
pipeline {
agent any
stages {
stage('Init') {
steps {
echo 'Hello!'
}
}
}
post {
failure {
office365ConnectorSend webhookUrl: "https://outlook.office.com/webhook/123456...",
factDefinitions: [[name: "fact1", template: "content of fact1"],
[name: "fact2", template: "content of fact2"]]
}
}
}
pipeline {
agent any
stages {
stage('Init') {
steps {
echo 'Hello!'
}
}
}
post {
failure {
office365ConnectorSend webhookUrl: "https://prod.westeurope.logic.azure.com:443/workflows...",
message: 'Something went wrong',
status: 'Failure',
adaptiveCards: true
}
}
}
Jenkins has the capability to execute Groovy scripts on launch by placing them in $JENKINS_HOME/init.groovy.d
.
The following script will configure the Office 365 Connector globally every time Jenkins starts:
import jenkins.model.Jenkins
import jenkins.plugins.office365connector.Webhook.DescriptorImpl
o365Connectors = Jenkins.get().getExtensionList(DescriptorImpl)
if (o365Connectors.size() == 0) {
throw new ClassNotFoundException('The Office 365 Connector Plugin must be installed to be configured')
} else {
o365Connector = o365Connectors[0]
}
String o365Url = 'https://example.webhook.office.com/webhookb2/07386f1b-1bc6-499f-ab7f-c9cf5e530cad@8f83d7b1-53ef-4906-a98e-9b8c4c3405b6/appId/852d8dec9176427b91f3658afb9e2513/9116b5aa-2a47-4248-88c2-41ef7340c222'
String o365Name = 'O365_Webhook'
o365Connector.setGlobalUrl(o365Url)
o365Connector.setGlobalName(o365Name)
You may find useful below link if you like to contribute and add new feature: