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

Kgn-web picture Kgn-web · Jun 6, 2018 · Viewed 14.6k times · Source

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??

Answer

Wah Yuen picture Wah Yuen · Jun 7, 2018

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