Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Publishing build artifacts failed with an error: Not found PathtoPublish: D:\a\1\s\$(buildStagingDirectory)

Building CI pipeline for .Net core APIs in VSTS. But while building getting the below error.

Publishing build artifacts failed with an error: Not found PathtoPublish: D:\a\1\s\$(buildStagingDirectory)

This is my build definition looks like

enter image description here

I have mentioned PathToPublish as $(buildStagingDirectory)

How do I get rid of this error??

like image 245
Kgn-web Avatar asked Jun 06 '18 11:06

Kgn-web


People also ask

How do I publish artifacts to Azure artifacts?

If you're using a private Windows agent, you can set the artifact publish location option (TFS 2018 RTM and older: artifact type) to publish your files to a UNC file share. Use a Windows build agent. This option doesn't work for macOS and Linux agents. Choose file share to copy the artifact to a file share.

How do you publish artifacts in release pipeline?

Publish pipeline artifacts is not supported in release pipelines. It is only supported in build pipelines, multi-stage pipelines, and yaml pipelines. You can publish your Artifacts at any stage of your pipeline using YAML or the classic editor.

What is build ArtifactStagingDirectory?

Build.ArtifactStagingDirectory. The local path on the agent where any artifacts are copied to before being pushed to their destination. For example: c:\agent_work\1\a. A typical way to use this folder is to publish your build artifacts with the Copy files and Publish build artifacts tasks. Note: Build.


2 Answers

I just encounted the exact same error.

Cause

After setting the system.debug variable to true, it revealed that the publish task actually performs a zip of the output folder (which by default is $(build.artifactstagingdirectory)) and places this 1 level higher in the directory structure. It then proceeds to delete the actual folder itself! I'm not sure if this is intended at all or a bug.

Workaround

After observing the above, I simply had the output of the publish task write to $(build.artifactstagingdirectory)\artifact and the resulting Publish Artifact task was then happy to pick up the zip file as it was still pointing to $(build.artifactstagingdirectory)

Default Publish Task output that fails

2018-06-07T02:24:17.8506434Z ##[debug]Zip Source: D:\a\1\a
2018-06-07T02:24:17.8508216Z ##[debug]Zip arguments: Source: D:\a\1\a , target: D:\a\1\a.zip
2018-06-07T02:24:18.0627499Z ##[debug]Successfully created archive D:\a\1\a.zip
2018-06-07T02:24:18.0628200Z ##[debug]rm -rf D:\a\1\a
2018-06-07T02:24:18.0629858Z ##[debug]removing directory
...
...
2018-06-07T02:24:18.3052522Z ##[error]Publishing build artifacts failed with an error: Not found PathtoPublish: D:\a\1\a

Modified output after adding extra directory

2018-06-07T02:38:59.8138062Z ##[debug]Zip Source: D:\a\1\a\artifact
2018-06-07T02:38:59.8139294Z ##[debug]Zip arguments: Source: D:\a\1\a\artifact , target: D:\a\1\a\artifact.zip
2018-06-07T02:39:00.0331460Z ##[debug]Successfully created archive D:\a\1\a\artifact.zip
2018-06-07T02:39:00.0334435Z ##[debug]rm -rf D:\a\1\a\artifact
2018-06-07T02:39:00.0336336Z ##[debug]removing directory
...
...
2018-06-07T02:39:00.4157615Z Uploading 1 files
2018-06-07T02:39:01.9425586Z ##[debug]File: 'D:\a\1\a\artifact.zip' took 1504 milliseconds to finish upload
like image 150
Wah Yuen Avatar answered Sep 27 '22 18:09

Wah Yuen


The way I normally tackle this issue is, first, to use the PublishPipelineArtifact@0 task, instead of the deprecated PublishBuildArtifacts@1. So, in YAML, I would replace:

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

for:

- task: PublishPipelineArtifact@0
  displayName: 'Publish pipeline artifact'
  inputs:
    artifactName: 'drop'
    targetPath: '$(Build.ArtifactStagingDirectory)'

If I would continue having this error, then I would set the pipeline variable system.debug to true, trigger the pipeline again, and observe the logs from the tasks that produce the artifacts I want to publish. The path should be there somewhere in those logs

like image 33
ccoutinho Avatar answered Sep 27 '22 17:09

ccoutinho