Skip to content

Latest commit

 

History

History
215 lines (164 loc) · 7.87 KB

README.md

File metadata and controls

215 lines (164 loc) · 7.87 KB

Github build Build Status

Coverage Status Popularity

Office-365-Connector

Office 365 Connector plugin for Jenkins

Plugin is used to send actionable messages in Outlook, Office 365 Groups, and Microsoft Teams.

Screenshots

Jenkins configuration

Configuration

Jenkins global configuration

GlobalConfiguration

Global configuration values used as default in jobs

GlobalConfigurationDefault

Microsoft Teams

With Jenkins plugin

Teams

With generic webhook connection

Webhook

Microsoft Outlook

Outlook

Jenkins Instructions

  1. Install this plugin on your Jenkins server
  2. 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.

Examples

DSL

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')
        }
    }
}

DSL Pipeline Job

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 properties

pipeline {

    agent any

    options {
        office365ConnectorWebhooks([[
            name: 'Office 365',
            startNotification: true,
            url: 'https://outlook.office.com/webhook/123456...'
        ]])
    }

    stages {
        stage('Init') {
            steps {
                echo 'Starting!'
            }
        }
    }
}

Pipeline step

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 post section

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"]]
        }
    }
}

Global Configuration in Init Hook

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)

Documentation

You may find useful below link if you like to contribute and add new feature: