OpsTrailsDocs
Console

Jenkins

Track events from Jenkins pipelines using the OpsTrails shared library.

Setup

  1. Go to Manage Jenkins → System → Global Pipeline Libraries
  2. Add a library with name opstrails and repository URL https://github.com/OpsTrails/jenkins-shared-library.git
  3. Store your API key as a Jenkins credential (Secret text) with ID opstrails-api-key

Pipeline Step

groovy
@Library('opstrails') _

pipeline {
  agent any
  environment {
    OPSTRAILS_API_KEY = credentials('opstrails-api-key')
  }
  stages {
    stage('Deploy') {
      steps {
        sh './deploy.sh'
      }
      post {
        success {
          opstrailsTrackEvent(
            type: 'deployment',
            source: "//jenkins/${env.JOB_NAME}",
            subject: 'production',
            version: env.BUILD_TAG
          )
        }
      }
    }
  }
}

opstrailsTrackEvent Parameters

ParameterRequiredDescription
typerequiredEvent type
sourceoptionalEvent source URI (defaults to job name)
subjectoptionalTarget environment
versionoptionalRelease version or build tag