I am currently attempting to migrate a Jenkins pipeline script to Azure Pipelines. In the Jenkins build, a local Dockerfile is used to setup an agent and run several Maven commands. The Dockerfile looks like this:
FROM maven:3.9.0-eclipse-temurin-17
RUN apt-get update && apt-get install -y openjdk-17-jdk xvfb
I'm trying to convert this setup into an azure-pipelines.yml
file where I build the Docker image in one job to be used in a subsequent job:
jobs:
- job: buildImage
pool:
vmImage: 'ubuntu-latest'
steps:
- task: Docker@2
inputs:
command: 'build'
Dockerfile: 'Dockerfile'
tags: 'buildimage:latest'
- job: buildJar
displayName: Build jar
dependsOn:
- buildImage
timeoutInMinutes: 10
container:
image: buildimage:latest
steps:
- script: 'mvn clean install'
The issue is that the buildJar job is unable to find the local image buildimage:latest
built in the buildImage job. Is it possible to set this up in the way I've envisioned it? Or should I first push the image to a private registry, use a private agent, or consider an alternative approach? Any suggestions would be greatly appreciated.
When you use the Microsoft provided cloud-hosted agents, they're recycled after each job, so you can't make assumptions about the local environment between jobs.
To reuse containers, the container registry is the most common approach.
If your docker container is just a specific set of JDK tooling and doesn't change frequently, I would use a separate pipeline to create and push the container image.
To use the container registry, you'll need to specify the service-connection as an endpoint.
- job: buildJar
container:
image: buildimage:latest
endpoint: mycontainer_registry_service_connection
steps:
- script: 'mvn clean install'