Skip to content

A library of Dynatrace functions that can be used within a Jenkins pipeline

License

Notifications You must be signed in to change notification settings

dt-demos/dynatrace-jenkins-library

 
 

Repository files navigation

Overview

Jenkins shared library for integrating calls the Dynatrace API with your Jenkins Pipelines.

Usage

The directive @Library('dynatrace@master') is added to the top of a Jenkinsfile script to load the latest version of the Dynatrace Jenkins library. Then within the various pipeline stages, Dynatrace library functions are called with the required and optional parameters that map to the required by the Dynatrace API requests. The Dynatrace URL and API token is configured within Jenkins or can be optionally passed as a parameter to the function call.

Library versions are listed below:

Library Version Comment
1.0 Initial Release
1.1 Add documentation. Remove deprecated Dynatrace push, jmeter, and keptn functions

It is recommended to specify the library version in the Jenkinsfile to ensure pipeline stability. For example @Library('dynatrace@1.1')

Library functions:

1. Push Information Events

  • Send deployment, configuration, and testing Dynatrace informational events.
  • Information Events usage details.

2. Problems

  • Dyntrace problem related functions
  • Problems usage details.

3. Configuration

  • Dynatrace configuration functions that show various examples to perform Dynatrace configurations
  • Configuration usage details.

Once you have everything configured use it in your Jenkins Pipeline like this

// Import Dynatrace library
@Library("dynatrace@master")

// Initialize the class with the event methods
def event = new com.dynatrace.ace.Event()

// this is called with a script step
def status = event.pushDynatraceDeploymentEvent() (
  tagRule: tagMatchRules,
  deploymentName: "myDeploymentJob: ${env.JOB_NAME}",
  deploymentVersion: "myDeploymentVersion",
  deploymentProject: "myDeploymentProject",
  remediationAction: "myRemediationAction",
  customProperties : [
    "Jenkins Build Number": env.BUILD_ID
  ]
)

Setup

Prerequisites

#1 - Jenkins server

You may have your own, but if not one option is to run Jenkins as Docker container. This command will start it up and prompt for setting up initial user and default plugins.

docker run -p 8080:8080 -p 50000:50000 -v jenkins_home:/var/jenkins_home jenkins/jenkins:lts

#2 Pre-Requisits on Jenkins

This Jenkins Shared Library requires the following Jenkins Plugins to be installed on your Jenkins server.

Jenkins Plugin Comment Tested Version
httpRequest Plugin Uses httpRequest to make REST Calls to Keptn Tested with 1.8.26

To install and verify plugins, navigate to Manage Plugins.

#3 - Dynatrace tenant and API Token

If you don't have Dynatrace, then sign up for a free trial. To generate a Dynatrace API token, follow these steps:

  1. Select Settings in the navigation menu.
  2. Go to Integration > Dynatrace API.
  3. Select Generate token.
  4. Enter a name for your token.
  5. You can accept the default, but you need API v1 Read and Write configuration permissions
  6. Select Generate.

Install and configure the Dynatrace Jenkins Library

  1. Login to Jenkins

  2. Navigate to Manage Jenkins > Configure System

  3. Find the Global Pipeline Libraries section, click add new and fill in as shown below

Configure the Dynatrace URL and API Token

The Dynatrace URL and API Token can be passed into the function calls, but by default they look for Jenkins environment variables for these values.

These values can be set in the Global properties section of Jenkins, but the recommended way is to configure these secrets as Global credentials so that Jenkins masks the value in any Jenkins logs. Below are the instructions for this approach.

  1. Login to Jenkins

  2. Navigate to Manage Jenkins > Manage Credentials

  3. Click on the (global) scope within the Stores scoped to Jenksins section.

  4. Click the Add creditials menu optioj

  5. Fill in the values as follows:

    1 . Kind = Secret Text

    2 . Secret = The URL to your Dynatrace tenant

    3 . ID = DT_TENANT_URL

  1. Click OK to save. Then click the Add creditials menu option again

  2. Fill in the values as follows:

    1 . Kind = Secret Text

    2 . Secret = The API token created for you Dynatrace tenant

    3 . ID = DT_API_TOKEN

  3. Click OK to save. When you are done, you should see this.

Support

If you’d like help with this pipe, or you have an issue or feature request, let us know. The repo is maintained by Dynatrace. You can contact us directly at ace@dynatrace.com.

If you’re reporting an issue, please include:

  • the version of the pipe
  • relevant logs and error messages
  • steps to reproduce

About

A library of Dynatrace functions that can be used within a Jenkins pipeline

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Groovy 97.7%
  • HTML 2.3%