Migrating from PublishBuildArtifact to PublishPipelineArtifact

Viewed 28

I am trying to publish artifacts after building our .Net MAUI app on Azure Devops pipeline. It works when I do it like this:

- task: PublishBuildArtifact@1
displayName: 'Publish Artifact: drop'
inputs:
  PathtoPublish: '$(Build.ArtifactStagingDirectory)/'
  ArtifactName: 'drop'
  publishLocation: 'Container'

After the pipeline runs, expected artifacts are created.

But I read that “PublishBuildArtfact” task is basically deprecated, and I should be using the “PublishPipelineArtifact” task. I tried to replace it as this:

- task: PublishPipelineArtifact@1
displayName: 'Publish Artifact: drop'
inputs:
  targetPath: '$(Build.ArtifactStagingDirectory)/'
  ArtifactName: 'drop'
  artifactType: 'pipeline'

But no artifacts are created. What am I missing?

1 Answers

According to your YAML, it seems you just publish again not migrating it. There is an example in the official document to show how to migrate from PublishBuildArtifact to PublishPipelineArtifact:

- task: PublishPipelineArtifact@1
 displayName: 'Publish'
 inputs:
  targetPath: $(Build.ArtifactStagingDirectory)/**
  ${{ if eq(variables['Build.SourceBranchName'], 'main') }}:
      artifactName: 'prod'
  ${{ else }}:
      artifactName: 'dev'
  artifactType: 'pipeline'

For more information, you can check the official document about migrating.

Related