You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure发布流水线:Docker阶段间工件共享方法咨询

Hey there! Let's walk through exactly how to set up your Azure DevOps release pipeline to handle this workflow—where stages 1 and 2 run independently, generate their JSON results, and stage 3 waits for both to finish before using those files. Here's a practical, step-by-step solution:

Core Approach

The key here is twofold: setting up proper stage dependencies so stage 3 only runs after 1 and 2 complete, and sharing the generated JSON files between stages using Azure DevOps artifacts (since each stage runs in its own Docker container, files aren't automatically shared).

Step-by-Step Implementation

1. Configure Stage Dependencies

First, make sure stage 3 waits for both stage 1 and stage 2 to finish successfully:

  • Open your release pipeline in the Azure DevOps editor
  • Click on the Stage 3 box, then go to the Dependencies tab in the right panel
  • Check the boxes for both Stage 1 and Stage 2, and set the condition to "Only when all previous stages have succeeded" (adjust if you need to handle failures differently)
  • Optional: Set Stage 1 and Stage 2 to run in parallel to save time—just drag them to be side-by-side in the pipeline editor, or leave their dependencies unset (they’ll run concurrently by default)

2. Publish Results from Stages 1 and 2

Each stage's Docker container generates results inside the container, so we need to copy those files to the Azure DevOps agent's local filesystem, then publish them as artifacts to share with stage 3.

For Stage 1:

  • After your docker run command that generates results1.json, add a Command Line task to copy the file from the container to the agent's working directory:
    # Replace <container-name/id> with your Docker container's name or ID, and <container-file-path> with where results1.json lives inside the container
    docker cp <container-name/id>:<container-file-path>/results1.json $(System.DefaultWorkingDirectory)/results1.json
    # Optional: Clean up the container if you don't need it anymore
    docker stop <container-name/id>
    docker rm <container-name/id>
    
  • Add a Publish Pipeline Artifacts task (preferred over Build Artifacts for newer pipelines) with these settings:
    • Artifact name: stage1-results
    • Target path: $(System.DefaultWorkingDirectory)/results1.json
    • Artifact publish location: Azure Pipelines

Repeat this exact process for Stage 2, replacing results1.json with results2.json and stage1-results with stage2-results.

3. Download Artifacts and Run Stage 3

In Stage 3, we'll first download both sets of results, then mount them into the Docker container for processing:

  • Add a Download Pipeline Artifacts task for stage 1's results:
    • Artifact name: stage1-results
    • Download path: $(System.DefaultWorkingDirectory)/stage1
  • Add another Download Pipeline Artifacts task for stage 2's results:
    • Artifact name: stage2-results
    • Download path: $(System.DefaultWorkingDirectory)/stage2
  • Now, run your Stage 3 Docker container with volume mounts to access the downloaded files:
    # Mount the stage1 and stage2 result directories into the container
    docker run -v $(System.DefaultWorkingDirectory)/stage1:/app/stage1 -v $(System.DefaultWorkingDirectory)/stage2:/app/stage2 <your-stage3-image-name>
    
    Inside your Stage 3 Docker image, you can now access the files at /app/stage1/results1.json and /app/stage2/results2.json.
Key Notes & Optimizations
  • If you use docker run --rm when starting your containers in stages 1 and 2, the container will automatically delete after it finishes running—saving you from having to manually stop/remove it.
  • Double-check file paths! The $(System.DefaultWorkingDirectory) variable points to the agent's root working folder, so make sure your docker cp command copies files there correctly.
  • For self-hosted agents, ensure you have enough disk space to store the artifacts temporarily. For Microsoft-hosted agents, artifacts are stored in Azure Pipelines storage, so you don't have to worry about losing files when the agent is recycled.

内容的提问来源于stack exchange,提问作者Matthewek

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 08:54:53