Skip to content
Latchkey

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_USER before the shell sees it.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →