Jenkins Integration

Jenkins is an open source automation server which enables developers around the world to reliably build, test, and deploy their software.

148

What does Opsgenie offer Jenkins users?

Use Opsgenie Jenkins Integration to forward Jenkins build alerts to Opsgenie. Opsgenie determines the right people to notify based on on-call schedules– notifies via email, text messages (SMS), phone calls, and iOS & Android push notifications, and escalates alerts until the alert is acknowledged or closed.

Functionality of the integration

When a build related problem occurs in Jenkins, an alert is created in Opsgenie automatically through the integration.

Add Jenkins Integration to Opsgenie

  1. Please create an Opsgenie account if you haven't done so already.
  2. Go to Opsgenie Jenkins Integration page.

🚧

For Free and Essentials plans, you can only add the integrations from the Team Dashboards, please use the alternative instructions given below to add this integration.

  1. Specify who is notified of Jenkins alerts using the Teams field. Auto-complete suggestions are provided as you type.

📘

An alternative for Step 2) and Step 3) is to add the integration from the Team Dashboard of the team which will own the integration. To add an integration directly to a team, navigate to the Team Dashboard and open Integrations tab. Click Add Integration and select the integration that you would like to add.

  1. Copy the URL and API Key and paste it into plugin's "Opsgenie Api URL" and "API Key" fields respectively.
  2. Click Save Integration.
2006

Install and Configure Opsgenie Jenkins Plugin

  1. In the Jenkins machine go to "Manage Jenkins" -> "Go to plugin manager" -> "Available" and search for Opsgenie Plugin, select and install it.
  2. Go back to Jenkins main page and go to "Manage Jenkins" -> "Configure System" -> "Opsgenie Notifier Settings" in order to set Global Plugin Configuration.
  3. Global Settings:
2094
  • Enter the API URL and API Key that's given from Opsgenie Jenkins Integration. API URL is set to a default value but also can be configured.
  • Enter the Teams to notify and alert Tags.
  • These fields are used as default settings, override them for specific jobs.
  1. Post-Build Action:
634
  • Activate Opsgenie Plugin for the Jenkins Job by following -> "Configure".
  • Scroll to the "Post-Build Actions" section of the project configuration.
  • Click "Add post-build action".
  • Select "Send Alert to Opsgenie" from the list displayed. The "Send Alert to Opsgenie" section appears in the window.
  • Click Save to retain these changes.
  1. Job Configuration:
1802
  • Configure the Jenkins Job settings for Opsgenie plugin by following -> "Configure" -> "Send Alert to Opsgenie".
  • Check "Enable Sending Alerts" to send an alert to Opsgenie.
  • Check "Notify Build Start" to send an alert to Opsgenie that notifies on build start.
  • Enter the API URL and API Key that's given from Opsgenie Jenkins Integration. If these fields are filled, global settings are overridden.
  • Enter the Teams to notify and alert Tags. Fill these fields to override global settings.
  • Select the priority of the build status alert from "Priority" field.
  • Select the priority of the build start status alert from "Build Start Alert's Priority" field.
  1. For more information about plugin you can check Opsgenie Plugin and our open source project Opsgenie Jenkins Plugin

Opsgenie Step Function Configuration

You can call Opsgenie Trigger Step function from your pipeline stages or post actions. Opsgenie Step function can be called with the following parameters(or without any parameter): tags(comma separated), teams(comma separated), priority, apiKey and apiUrl
An example request would be the following:

opsgenie(tags: "tag1,tag2" ,  teams: "team1",  priority: "P1")

🚧

API Key and API Url

You can configure API key and API url from Manage Jenkins -> Configure System -> Opsgenie Notifier Settings.
You can also override API key and API url from the step function call like following: opsgenie(apiKey: "myApiKey", apiUrl: "myApiUrl")

An example pipeline script:

pipeline {
    agent any
    stages {
        stage('pre') {
            steps {
                sh 'echo "pre success!"; exit 0'
            }
        }
        stage('post') {
            steps {
                sh 'echo "post success!"; exit 0'
            }
        }
        stage('Test') {
            steps {
                sh 'echo "Failed!"; exit 1'
            }
        }
    }
    post {
        always {
            echo 'This will always run'
        }
        success {
            echo 'This will run only if successful'
	          opsgenie(tags: "informational")
        }
        failure {
            echo 'This will run only if failed'
            opsgenie(tags: "failure, critical", 
                     teams: "engineering", priority:"P1")
        }
        unstable {
            echo 'This will run only if the run was marked as unstable'
            opsgenie()
        }
        changed {
            echo 'This will run only if the state of the Pipeline has changed'
            echo 'For example, if the Pipeline was previously failing but is now successful'
        }
    }
}