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

多阶段流水线作业间文件共享方法及可行性咨询:dotnet publish输出无法被访问

Hey there! Let's break down your questions one by one and fix that artifact publishing issue you're running into.

1. 如何在作业之间共享文件?

Jobs in CI/CD pipelines run in isolated environments (think separate containers or VMs) by default, so their file systems don't overlap. To share files between them, you'll need to use build artifacts—this is the standard way to pass build outputs, binaries, or any generated files from one job to another.

The basic workflow goes like this:

  • In the job that generates the files (like your dotnet publish job), add a step to upload those files as an artifact to your pipeline's built-in artifact storage.
  • In the downstream job (your publish artifacts job), add a step to download that artifact first—once it's downloaded, the job can access the files just like any local file.
2. 多阶段流水线构建中两个作业是否可以共享文件?

Short answer: No, not directly. Even in multi-stage pipelines, each job gets its own fresh, isolated environment. The file system of one job isn't accessible to another unless you explicitly use artifacts (or cache, but cache is meant for reusing dependencies like NuGet packages, not build outputs).

Fixing your specific dotnet publish + publish artifacts issue

It sounds like your publish artifacts job can't access the dotnet publish output because you haven't set up the artifact upload/download flow. Here's a concrete example of how to fix this (using Azure DevOps YAML as a reference—adjust based on your CI/CD platform):

jobs:
# First job: Run dotnet publish and upload the output as an artifact
- job: DotNetPublishJob
  steps:
  # Run dotnet publish, outputting to a dedicated staging directory
  - task: DotNetCoreCLI@2
    inputs:
      command: 'publish'
      publishWebProjects: true
      arguments: '--configuration Release --output $(Build.ArtifactStagingDirectory)/publish'
  
  # Upload the publish output as a pipeline artifact
  - task: PublishBuildArtifacts@1
    inputs:
      PathtoPublish: '$(Build.ArtifactStagingDirectory)/publish'
      ArtifactName: 'dotnet-publish-files'
      publishLocation: 'Container'

# Second job: Download the artifact and publish it
- job: PublishArtifactsJob
  # Ensure this job runs only after the first job finishes successfully
  dependsOn: DotNetPublishJob
  steps:
  # Download the artifact we uploaded earlier
  - task: DownloadBuildArtifacts@0
    inputs:
      buildType: 'current'
      downloadType: 'single'
      artifactName: 'dotnet-publish-files'
      downloadPath: '$(System.ArtifactsDirectory)'
  
  # Now you can run your publish artifacts task—point it to the downloaded path
  # For example, if uploading to external storage, use: $(System.ArtifactsDirectory)/dotnet-publish-files

Key checks to avoid issues:

  • Make sure dependsOn is set so the second job waits for the first one to complete.
  • Double-check the artifact name matches exactly between the upload and download steps (no typos!).
  • Verify the output path from dotnet publish matches the path you're uploading—if you're not using $(Build.ArtifactStagingDirectory), confirm the absolute path is correct.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.14 07:54:48