Azure DevOps Publish and Download Artifacts
This post is to talk about one minor thing, but that took me a couple hours to fix. It’s about using the tasks to publish and download artifacts.
I read several blog posts and the Microsoft documentation and all examples are pointing out that I can use the system location $(Build.ArtifactStagingLocation) when doing the publishing during my build phase.
So that’s what I did as you can see in the code below:
And according to these blog posts and documentation I can use the same location to retrieve the artifact during my deployment phase.
So I did the following code to do so:
But this does not work. It keeps saying that it cannot find the file, but checking the logs I could see it was being generated properly.
Below you can see the error message I was getting:

I added a few debug steps to check the location of know system variables to understand what was going on using a powershell script as below:
With that I could see that the location it was looking was not the same as the location where the package was being published.
The $(Build.ArtifactStagingDirectory) was returning d:\a\1\a but the file was being downloaded to d:\a\1.
With the debugging script above, I could see that this location is the one present at $(Pipeline.Workspace), which was happening automatically.
The Microsoft documentation is very confusing but finally I found one that helped me in pointing to the solution at: https://docs.microsoft.com/en-us/azure/devops/pipelines/artifacts/pipeline-artifacts?view=azure-devops&tabs=yaml-task#artifact-selection.
In there is explaining that I can define where I can download the artifacts to with the following task:
Now I can define exactly where I want to download the artifacts to. Please be aware that the download happens automatically to $(Pipeline.Workspace), so if you don’t want you deployment to download the files twice, you need to specify the “download: none” in your steps.
Summary
I don’t know if this was a recent change or not, but all blog posts pointing to the same system variable with no mention to this finding that I got seems very strange to me. It would be really good to know if someone out there is having the same problem as me.
Comments
Post a Comment