Run Datadog Synthetic Tests in Your Jenkins Pipelines | Datadog

Run Datadog Synthetic tests in your Jenkins pipelines

Author Kai Xin Tai
Author Beth Glenfield

Published: January 26, 2022

Continuous integration (CI) has become the mainstream approach to software development as it enables organizations to iterate quickly while minimizing the risk of releasing faulty code. To implement CI, many organizations rely on Jenkins—one of the most mature and widely used automation servers on the market. Jenkins comes with hundreds of community-backed plugins to help you easily integrate it with other tools in your development workflow. The Datadog plugin, for instance, collects metrics and events on Jenkins jobs, and then forwards them to Datadog for monitoring and analysis.

In addition to understanding the activity on your Jenkins instances, it is also crucial to implement automated testing within your CI process so that you can detect and address issues before they make it into production. Datadog Synthetic Monitoring offers a comprehensive suite of tests that enable you to verify whether your end users are able to successfully complete key application workflows from end to end. Now, you can run Synthetic tests as part of your Jenkins pipelines to gain visibility into your applications as you’re developing them. In this post, we’ll show you how to add these tests to Jenkins and monitor their results in Datadog.

Add Synthetic tests to your existing Jenkins pipelines

Datadog Synthetic Monitoring is designed with a simple-to-use interface that enables anyone on your team, regardless of their coding experience, to write end-to-end tests. Tests are abstracted from their parameters, which allows you to use a single test suite for all of your environments (e.g., production, staging, development), including your Jenkins pipelines. You can then leverage the @datadog/datadog-ci NPM package to easily run the tests within your existing Jenkins pipelines, removing the need to write complex scripts.

To get started, head over to the Jenkins Global Configuration panel and install Node.js v10.24.0+, as well as the @datadog/datadog-ci package.

Install Node.js and datadog-ci package

Next, upload a global configuration file, which includes your Datadog API and Application keys, via the Config File Provider. Your global configuration file should also include the path to your .synthetics.json file, which contains the IDs of the Synthetic tests you’d like to run. To complete the process, modify your existing pipeline configuration to include a test stage, which we’ve named Run e2e tests in the example below.

pipeline {
   agent any
   stages {
       stage('Run e2e tests') {
           steps {
               withCredentials([string(credentialsId: 'datadog-api-key', variable: 'DATADOG_API_KEY'), string(credentialsId: 'datadog-app-key', variable: 'DATADOG_APP_KEY')]) {
                   nodejs(nodeJSInstallationName: 'Node 10.24.x') {
                       configFileProvider(
                           [configFile(fileId: 'config-file-id', variable: 'DATADOG_CI_CONFIG')]) {
                           sh 'datadog-ci synthetics run-tests --config $DATADOG_CI_CONFIG'
                       }
                   }
               }  
           }
       }
   }

If you’ve followed the steps we outlined above, this pipeline will prompt Jenkins to autodiscover and run all of the tests you’ve included in your synthetics.json file. You can then view your test results directly in Jenkins, as shown here:

View test results in Jenkins

Refer to our documentation for more information on configuring and executing tests.

Monitor Synthetic test results and Jenkins performance in Datadog

In addition to viewing your Synthetic test results in Jenkins, you can also monitor them in the Datadog CI Results Explorer. For each test batch, the CI Results Explorer displays its summary status and duration, as well as other details, to help you easily spot potential issues. Batches are tagged with metadata, such as branch and pipeline ID, which allows you to narrow your focus to the segment you’re most interested in. You can also click on any test batch to compare the results of individual test runs across different browsers, devices, and locations.

View your Jenkins test results in the Datadog CI Results Explorer

For even greater insight into your Jenkins workflows, Datadog CI Visibility provides key performance metrics for pipelines, build stages, and jobs. If, for instance, you see an error in an early build stage that is causing your tests to fail, you can examine a flame graph to pinpoint the problematic job.

Release software faster without sacrificing quality

Datadog Synthetic tests can now be run within Jenkins pipelines, as well as with the new Datadog Github Action, so you can test your application workflows earlier and more frequently during the development cycle. Datadog Synthetic Monitoring can also be paired with CI Visibility, which provides insight into the performance of the CI pipelines in which your Synthetic tests run. We plan to add support for more CI/CD providers in the coming months, so stay tuned.

If you’re new to Datadog, sign up for a 14-day today.