最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Create (and use) a local docker image in Azure Pipelines - Stack Overflow

programmeradmin2浏览0评论

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.

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.

Share Improve this question edited Jan 22 at 14:57 Michiel asked Jan 22 at 14:50 MichielMichiel 3,5102 gold badges30 silver badges42 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

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'
发布评论

评论列表(0)

  1. 暂无评论