Skip to main content

Jenkins

Dagger runs your checks in Jenkins via dagger check, so the same checks you run locally run on every job — without rewriting your pipeline. You keep all of your existing Jenkins infrastructure and Jenkinsfile, and simply invoke the Dagger CLI from it.

tip

For checks with no Jenkinsfile changes at all, enable Cloud Checks with dagger ws autocheck on. The Jenkinsfile below is the hybrid-mode alternative for when you want to drive Dagger from your existing Jenkins setup.

How it works​

There are many ways to run Dagger on Jenkins. The simplest way to get started is having a Jenkins agent with OCI compatible container runtime.

The general workflow looks like this:

  1. Jenkins receives job trigger as usual.
  2. Jenkins loads Jenkinsfile from repository or from UI configuration.
  3. Jenkins parses the Groovy-based Jenkinsfile and downloads the Dagger CLI.
  4. Jenkins runs dagger check against the modules installed in your workspace.
  5. The Dagger CLI attempts to find an existing Dagger Engine or spins up a new one inside the Jenkins agent, and sends telemetry to Dagger Cloud if the DAGGER_CLOUD_TOKEN environment variable is set.
  6. Job completes with success or failure based on the check results, pipeline logs appear in Jenkins as usual

Prerequisites​

Running the examples shown below requires:

  1. At least one Jenkins agent with the dagger label
  2. A Docker engine that is able to run containers (can be docker:dind)
  3. The docker client installed on your Jenkins agent
  4. A repository with a Dagger workspace (.dagger/config.toml) — see Workspace Setup.

Example​

The following code sample demonstrates how to run your Dagger checks in Jenkins. dagger check runs all checks from the modules installed in your workspace and exits non-zero if any check fails; scope it to a single module's checks with a pattern such as dagger check go:*.

Jenkinsfile
pipeline {
agent { label 'dagger' }

// assumes that the Dagger Cloud token
// is in a Jenkins credential named DAGGER_CLOUD_TOKEN
environment {
DAGGER_VERSION = "0.21.4"
PATH = "/tmp/dagger/bin:$PATH"
DAGGER_CLOUD_TOKEN = credentials('DAGGER_CLOUD_TOKEN')
}

stages {
stage("dagger") {
steps {
sh '''
curl -fsSL https://dl.dagger.io/dagger/install.sh | BIN_DIR=/tmp/dagger/bin DAGGER_VERSION=$DAGGER_VERSION sh
dagger check
'''
}
}
}
}

Dagger Cloud Engines​

By default the CLI starts a Dagger Engine inside the Jenkins agent. For a faster, more reliable experience, offload execution to a managed Dagger Engine provided by Dagger Cloud by adding --cloud to the command (dagger check --cloud). Cloud Engines provide a large persistent cache shared across runs and far more compute than a Jenkins agent, so checks are typically much faster — and you don't provision or maintain any infrastructure. This requires the DAGGER_CLOUD_TOKEN credential configured above.

Resources​

If you have any questions about additional ways to use Jenkins with Dagger, join our Discord and ask your questions in our Jenkins channel.

  • Introduction to running Dagger Pipelines with Jenkins by Lev Lazinskiy. In this demo, he shows how to integrate Dagger pipelines with Jenkins. He explains the setup process for a Jenkins pipeline using Dagger and covers both a simple and a modular approach to managing CI pipelines effectively.

About Jenkins​

Jenkins is an open-source automation server that enables teams to automate the build, test, and deploy processes of software projects. Jenkins supports many plugins that integrate with various tools, making it a popular choice for Continuous Integration and Continuous Deployment.