首页 > 解决方案 > use files from stage 1 in stage 2 in azure-pipeline

问题描述

I have a single pipeline in azure containing two stages: one for building and one for testing:

trigger:
- main

stages:
  - stage: 'Checkout'
    jobs:
      - job: 'x86'
        timeoutInMinutes: 60
        pool: <mypool>

        steps:
        - checkout: self
          lfs: true

  - stage: 'CompileAndTest'
    jobs:
      - job: 'UnitTests'
        timeoutInMinutes: 60
        pool: <mypool>
        
        steps:
        - task: MSBuild@1
          inputs:
            solution: '$(Build.SourcesDirectory)/MyAssembly.csproj'
            platform: 'x86'
            configuration: 'Debug'

When executing that pipeline, stage Checkout will first checkout the code to $(Build.SourceSirectory), which in my case resolved to D:\agents\build\_work\3\s.

Afterwards the stage CompileAndTest compiles the code. However MSBuild states

error MSB1009: project not found, project 'D:\agents\build\_work\4\s\MyAssembly.csproj'

So the variable Build.SourceDirectory resolves to different locations between the two stages.

My pool only has a single agent, so I'm sure both jobs run on the same agent.

标签: azure-pipelines

解决方案


Would recommend using the PublishBuildArtifacts task

Would look like:

- task: PublishBuildArtifacts@1
  inputs:
    pathToPublish: '$(Build.ArtifactStagingDirectory)' 
    artifactName: 'drop' 

The reference your folder via the $(Pipeline.Workspace) built in variable


推荐阅读