0
votes

So I am trying to copy file and publish it via Azure yaml pipeline task PublishBuildArtifacts@1 so that I can use that file in other pipeline by downloading build artifact.

      - script: |
          cat ./pipelines/config/abc.config
          mkdir $(Build.ArtifactStagingDirectory)/abc-config
          cp -R ./pipelines/config/abc.config $(Build.ArtifactStagingDirectory)/abc-config
        displayName: "Archiving runtime config file"

      # Publish Config Build Artifacts
      - task: PublishBuildArtifacts@1
        inputs:
          PathtoPublish: "$(Build.ArtifactStagingDirectory)/abc-config/"
          ArtifactName: "abc-config"
          publishLocation: "Container"

when I use the task DownloadBuildArtifacts@0 and download that file to a specific path, it supposed to store that file to ./pipelines/config/abc.config

but when I type ls to see if I get this file, for some reason I couldn't able to get that file.

      - task: DownloadBuildArtifacts@0
          inputs:
              buildType: 'current'
              project: '$(System.TeamProjectId)'
              pipeline: '$(System.DefinitionId)'
              downloadType: 'single'
              artifactName: 'abc-config'
              downloadPath: '$(System.ArtifactsDirectory)/pipelines/config'

      - bash: |
            # input file and remove empty lines and/or lines with crlf
            ls ./pipelines/config

pipeline Logs: logs show that it's trying to download that file by adding artifact name before that file. I don't understand this behavior of adding artifact name before the file name.

Downloading abc-config/runtime.config to /home/vsts/work/1/a/pipelines/abc-config/runtime.config
Downloaded abc-config/runtime.config to /home/vsts/work/1/a/pipelines/abc-config/runtime.config

What should I need to do to store that file to pipelines/config/runtime.config?

Documentation of task: DownloadBuildArtifacts@0 doesn't mention anything about this behavior. so I am not sure what am I missing here. Any help would be highly appreciated.

Thank you.

1

1 Answers

0
votes

When you publish build artifacts, the artifacts will be saved in the artifactName folder. So when you download them using DownloadBuildArtifacts task. The artifactName folder and all the artifacts contents will be downloaded. This is the default behavior.

As a workaround, you can change the artifactName to config for PublishBuildArtifacts task. See below:

- task: PublishBuildArtifacts@1
        inputs:
          PathtoPublish: "$(Build.ArtifactStagingDirectory)/abc-config/"
          ArtifactName: "config"
          publishLocation: "Container"

Then change the downloadPath to $(System.ArtifactsDirectory)/pipelines for DownloadBuildArtifacts task. See below:

 - task: DownloadBuildArtifacts@0
          inputs:
              buildType: 'current'
              project: '$(System.TeamProjectId)'
              pipeline: '$(System.DefinitionId)'
              downloadType: 'single'
              artifactName: 'config'
              downloadPath: '$(System.ArtifactsDirectory)/pipelines'