If you’re using an Azure DevOps pipeline to build a project/solution and publish an artifact, you may have run into the magical situation where your artifact is automatically (and bafflingly) named a.zip
.
But how? Why? I didn’t ask for this!
I agree dear reader! This is actually the second time I’ve run into this particular issue without any clear documentation on why it happens, so I decided to be the change I wanted to see in the world (by writing this blog post).
The Cause
There are a few moving parts that need to align for this to happen:
- You are using the
DotNetCoreCLI@2
task with thepublish
command, e.g:
- task: DotNetCoreCLI@2
inputs:
command: 'publish'
publishWebProjects: false
projects: '$(project)'
arguments: '--output $(Build.ArtifactStagingDirectory) --configuration $(buildConfiguration)'
modifyOutputPath: false
displayName: Publish my project
zipAfterPublish
istrue
(in the above example it is missing but the default istrue
, so unless it’s specifically declared asfalse
you can assume this is the case)- You’ve specified the
--output
flag with the$(Build.ArtifactStagingDirectory)
variable (with no relative path on the end). This may also extend to other generated paths that the pipeline gives you access to
But why do these particular elements aligning cause your archive to be called a.zip
? Because:
- The project is zipped using the name of the folder it is located in
- The path that
$(Build.ArtifactStagingDirectory)
expands to (in my instance) is…D:\a\1\a\
!
Aha!
The Fix
OK, so we know why it happens now, but how do we change it? Thankfully the fix is nice and simple!
- Change the
--output
flag to use a directory with the name that you actually want (for example,--output $(Build.ArtifactStagingDirectory)/MyArtifactName
- If you’re using the
PublishBuildArtifacts@1
task, update yourPathtoPublish
to the new directory:
- task: PublishBuildArtifacts@1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)/MyArtifactName'
ArtifactName: 'MyProjectArtifactName'
publishLocation: 'Container'
And voila!