0

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.

Auto geek
  • 464
  • 1
  • 6
  • 21

1 Answers1

0

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'
Levi Lu-MSFT
  • 27,483
  • 2
  • 31
  • 43
  • Thank you for your response. In the DownloadBuildArtifacts@0 task, shouldn't the name of the Artifact be 'pipelines' instead of 'config'? also, what this task does, it will download my file(abc.config) under the pipelines folder. which wouldn't solve the issue. since I want my file inside pipelines/config/abc.config – Auto geek Jun 07 '21 at 10:53
  • I've also renamed the ArtifactName to 'config' in the task PublishBuildArtifacts@1. and set the downloadPath to '$(System.ArtifactsDirectory)/pipelines'. so that I can get the file in the correct order which is pipelines/config/abc.config. but when I do "ls" it doesn't show this file in the config directory. and I can't understand this behavior either. @Levi Lu-MSFT – Auto geek Jun 07 '21 at 11:27
  • @Autogeek My mistake. I thought you wanted the file in `pipelines/runtime.config`?i updated above answer. It should work this time – Levi Lu-MSFT Jun 08 '21 at 02:28
  • I've tried that workaround already. but I'm still not getting the runtime.config file in the config directory. This is the log I am getting: "Successfully downloaded artifacts to /home/vsts/work/1/a/pipelines/" but when I do "ls" command to see that file, unfortunately, the file is not there. @Levi Lu-MSFT – Auto geek Jun 09 '21 at 12:31