5

I've got my yaml to run my build (which is a fake script), and I want to publish various outputs from the build script as an artifact.

I've half got it working, but I can't work out quite how to get some specific folder to be output.

  - task: PublishPipelineArtifact@1
    displayName: Publish Report
    inputs:
      pathToPublish: $(System.DefaultWorkingDirectory)/s/ReportProject/bin/Release/netcoreapp3.1
      artifactName: MyReport

what it actually seems to do is take some arbritrary folder (which is the name of my pipeline with the below as subfolders)

subfolders 
TestResults
a
b
s

yes, my app is in there, but so is everything, very odd.

I change the path...it publishes the same thing i.e. everything!

riQQ
  • 9,878
  • 7
  • 49
  • 66
MrD at KookerellaLtd
  • 2,412
  • 1
  • 15
  • 17

2 Answers2

11

When you use the predefined variables to refer to the folders in the build agent. You should know what the exact folders they are mapped to. See below example of a self-hosted agent:

enter image description here

$(Pipeline.Workspace) is mapped to c:\agent\_work\1

$(Agent.BuildDirectory) is also mapped to c:\agent\_work\1

$(Build.ArtifactStagingDirectory) is mapped to the a folder c:\agent\_work\1\a

$(Build.BinariesDirectory) is mapped to the b folder c:\agent\_work\1\b

$(Build.SourcesDirectory) is the same as $(System.DefaultWorkingDirectory) which is mapped to the s folder c:\agent\_work\1\s

The default working directory for the PublishPipelineArtifact task and also other tasks is $(System.DefaultWorkingDirectory) (ie. c:\agent\_work\1\s)

Since your project folder resides in the folder ReportProject under sfolder. That's why targetPath: 'ReportProject/bin/Release/netcoreapp3.1' works. Because it equals to $(System.DefaultWorkingDirectory)/ReportProject/bin/Release/netcoreapp3.1, and $(Pipeline.Workspace)/s/ReportProject/bin/Release/netcoreapp3.1,and $(Build.SourcesDirectory)/ReportProject/bin/Release/netcoreapp3.1. These will all work.

Levi Lu-MSFT
  • 27,483
  • 2
  • 31
  • 43
2

I used the yaml tooling in azure devops and that seemed to do this

  - task: PublishPipelineArtifact@1
    displayName: Publish Report
    inputs:
      targetPath: '$(Pipeline.Workspace)/s/ReportProject/bin/Release/netcoreapp3.1'
      artifact: 'MyReport'
      publishLocation: 'pipeline'

that works, I don't especially like knowing that the agent puts the repository in a folder called "s", but apart from that, it works.


this also works

  targetPath: 'ReportProject/bin/Release/netcoreapp3.1'

(I tried to get Build.SourcesDirectory to work but it failed)

MrD at KookerellaLtd
  • 2,412
  • 1
  • 15
  • 17
  • 1
    By using `Build.SourcesDirectory` you should get the path including the 's' folder (see https://learn.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml#build-variables-devops-services) – riQQ Oct 19 '20 at 16:55
  • 1
    doesnt seem to work for me. ##[error]Path does not exist: D:\a\1\s\$(PipelineBuild.SourcesDirectory)\bin\Release\netcoreapp3.1 – MrD at KookerellaLtd Oct 20 '20 at 08:17