DEV Community

Richard Spindler
Richard Spindler

Posted on

2 1

Howto use Docker Agent in a Jenkinsfile Matrix Build

There is one simple tutorial that I was looking for on the web, and I could not find it.

So I wrote it myself.

Jenkins has matrix builds, and Jenkins has agent docker for builds inside a docker image.

Combined, these features make it easy to test a project with multiple versions of PHP for example.

So here is the simple example I came up with: Put this in your Jenkinsfile and you are done.

pipeline {
    agent none
    stages {
        stage('Test') {
            matrix {
                agent {
                    docker { image "${DOCKER_IMAGE}" }
                }
                axes {
                    axis {
                        name 'DOCKER_IMAGE'
                        values 'php:5.3', 'php:5.6'
                    }
                }
                stages {
                    stage('Test') {
                        steps {
                            sh 'php --version'
                        }
                    }
                }
            }
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

Please let me know if it helps you 😊

Learning more

Testing your software in different environments is a best practice for software engineering.

If you like this article: I am writing a book about best practices for legacy code projects:

Leading a Legacy Software Team

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay