What's the best way to verify that a universal publish task actually uploads an artifact > 0mb, instead of an empty artifact?
For example, I had a job that was downloading a pipeline artifact from a previous job, then checking for various criteria, then uploading the previous job's artifact as a universal package. Due to a misfire on my part, the artifact was getting downloaded to the workspace, but the publish was pulling from the artifact staging directory. I caught that when I was less tired but with the way you can't overwrite any previously published packages with a version that's already set, now I've got to clean up some clutter. I'd like to avoid this pain in the future.
- job: "releasepublish"
dependsOn:
- "cicd"
condition: startsWith(variables['build.sourceBranch'], 'refs/heads/release')
variables:
outputVersion: $[ dependencies.cicd.outputs['windows.VersionNumber.appVersion'] ]
steps:
- task: DownloadPipelineArtifact@2
inputs:
buildType: 'current'
targetPath: '$(Pipeline.Workspace)'
- task: UniversalPackages@0
inputs:
command: 'publish'
publishDirectory: '$(Build.ArtifactStagingDirectory)'
feedsToUsePublish: 'internal'
vstsFeedPublish: '...'
vstsFeedPackagePublish: '$(Build.SourceBranchName)'
versionOption: 'custom'
versionPublish: '$(outputVersion)'
packagePublishDescription: 'master branch release $(outputVersion) for $(Build.SourceBranchName)'
the saddest success message in the world:
2021-03-09T14:49:27.2499973Z {"@t":"2021-03-09T14:49:26.6123086Z","@m":"\n
Content upload statistics:\n
Total Content: 0.0 MB\n
Physical Content Uploaded: 0.0 MB\n
Logical Content Uploaded: 0.0 MB\n
Compression Saved: 0.0 MB\nDeduplication Saved: 0.0 MB\n
Number of Chunks Uploaded: 0\n
Total Number of Chunks: 1\n
","@i":"13d73b85","SourceContext":"ArtifactTool.Commands.UPackPublishCommand","UtcTimestamp":"2021-03-09 14:49:26.612Z"}
...
2021-03-09T14:49:27.2504559Z {"@t":"2021-03-09T14:49:27.2346667Z","@m":"Success","@i":"1d9af52f","SourceContext":"ArtifactTool.Commands.UPackPublishCommand","UtcTimestamp":"2021-03-09 14:49:27.234Z"}
(tangentially, if you've got recs for handling node app package versions and azure artifacts versions, I'm all ears for better practice)
What's the best way to verify that a universal publish task actually uploads an artifact > 0mb, instead of an empty artifact?
A way is to use pre-release versions, such as 1.0.0-alpha
. After you confirm the content of the pre-release version artifact, then publish the artifact of official version, such as 1.0.0
.
A more cumbersome solution is to check whether the directory is empty before you publish an artifact.
Here is an example using PowerShell:
- task: PowerShell@2
inputs:
targetType: 'inline'
script: |
$directoryInfo = Get-ChildItem $(Build.ArtifactStagingDirectory) | Measure-Object
if ($directoryInfo.count -eq 0)
{
throw "EMPTY!"
}