Skip to main content

Jenkins

Dagger provides a programmable container engine that allows you to replace your Groovy-based Jenkins pipelines with a regular programming language. This allows you to execute your pipeline the same locally and in Jenkins, with intelligent caching, while keeping all of your existing Jenkins infrastructure.

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 repo or from UI config
  3. Jenkins parses the Groovy based Jenkinsfile and finds dagger call $foo
  4. Jenkins executes dagger call $foo
  5. Dagger CLI attempts to find an existing Dagger Engine or spins up a new one inside the Jenkins agent.
  6. Dagger Engine executes the pipeline called in dagger call $foo and sends telemetry to Dagger Cloud if the DAGGER_CLOUD_TOKEN environment variable is set.
  7. Job completes with success or failure, 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

Examples

The following code sample demonstrates how to integrate Dagger with Jenkins.

Jenkinsfile
pipeline {
agent { label 'dagger' }

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

stages {
stage("dagger") {
steps {
sh '''
curl -L https://dl.dagger.io/dagger/install.sh | BIN_DIR=/tmp/dagger/bin DAGGER_VERSION=$DAGGER_VERSION sh
dagger call -m github.com/shykes/hello hello --greeting "bonjour" --name "from jenkins"
'''
}
}
}
}

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.

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.