Skip to main content

Use Dagger SDKs in CI

Introduction

This guide explains how to integrate the Dagger SDKs with various CI services/tools.

Requirements

This guide assumes that:

  • You have a Go, Python or Node.js environment on the CI runner.
  • You have a Dagger SDK for one of the above languages installed on the CI runner. If not, install your preferred language SDK within your CI workflow following the installation instructions for the Dagger Go, Python or Node.js SDK.

Use Dagger in CI

GitHub Actions

.github/workflows/dagger.yml
name: dagger
on:
push:
branches: [main]

jobs:
build:
name: build
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
with:
go-version: '1.20'
- uses: actions/checkout@v3
- name: Run Dagger pipeline
run: go run main.go

GitLab CI

.gitlab-ci.yml
.docker:
image: golang:1.20-alpine
services:
- docker:${DOCKER_VERSION}-dind
variables:
DOCKER_HOST: tcp://docker:2376
DOCKER_TLS_VERIFY: '1'
DOCKER_TLS_CERTDIR: '/certs'
DOCKER_CERT_PATH: '/certs/client'
DOCKER_DRIVER: overlay2
DOCKER_VERSION: '20.10.16'
.dagger:
extends: [.docker]
before_script:
- apk add docker-cli
build:
extends: [.dagger]
script:
- go run main.go

CircleCI

.circleci/config.yml
version: 2.1
jobs:
build:
docker:
- image: cimg/go:1.20
steps:
- checkout
- setup_remote_docker:
docker_layer_caching: true
- run:
name: Dagger Pipeline
command: go run main.go
workflows:
dagger:
jobs:
- build

Jenkins

Jenkinsfile
pipeline {
agent { label 'dagger' }

stages {
stage("dagger") {
steps {
sh '''
go run main.go
'''
}
}
}
}

Requires docker client and go installed on your Jenkins agent, a Docker host available (can be docker:dind), and agents labeled in Jenkins with dagger.