How to Build a Multi-Arch Docker Image in a Jenkins Pipeline
Drive docker buildx from a Jenkins stage to cross-build amd64 + arm64 into one pushed manifest.
On an agent with Docker and Buildx, register QEMU emulators, create a builder, log in with bound credentials, then docker buildx build --platform ... --push.
Buildx in a stage
Install emulators, create a builder, then build both platforms and push under the build number tag.
Jenkinsfile
pipeline {
agent any
stages {
stage('Build multi-arch') {
steps {
withCredentials([usernamePassword(credentialsId: 'registry-creds',
usernameVariable: 'REG_USER', passwordVariable: 'REG_PASS')]) {
sh '''
echo "$REG_PASS" | docker login -u "$REG_USER" --password-stdin registry.example.com
docker run --privileged --rm tonistiigi/binfmt --install all
docker buildx create --use
docker buildx build \
--platform linux/amd64,linux/arm64 \
-t registry.example.com/myorg/app:${BUILD_NUMBER} \
--push .
'''
}
}
}
}
}Gotchas
- The agent needs Docker with Buildx and the ability to run a privileged container for QEMU registration.
- Buildx pushes the multi-platform manifest directly; you cannot load it into the agent's local daemon.
- Use triple single-quotes for the shell block so Groovy does not interpolate
$REG_USERbefore the shell sees it.
Related guides
How to Build a Multi-Arch Docker Image in GitHub ActionsBuild a multi-architecture Docker image (amd64 + arm64) in GitHub Actions with QEMU and Buildx, pushing a sin…
How to Build and Push a Docker Image in a Jenkins PipelineBuild and push a Docker image in a Jenkins pipeline with the Docker Pipeline plugin docker.build and withRegi…