Abhinav Kumar
Abhinav Kumar

Reputation: 31

Azure Pipeline Copy Selected folder

I am trying to build an Azure Pipeline using yaml that will copy selected folders (based on parameter to the pipeline) in CopyFilesOverSSH task, each directory should copy one by one. ERROR 'Unable to convert from Object to String. Value: Object' Azure Pipeline Copy Selective folder

I also tried ${{ convertToJson(directory) }}, it's converting complete collection in json and does not help in picking object one by one.

Or Please suggest alternative where I can copy selected folder based on parameter to the azure pipeline.

trigger: none

parameters:
- name: directoryList
  type: object
  default:
    directoryList:
    - 'LOL-01'
    - 'LOL-02'
    - 'LOL-03'

pool:
  vmImage: ubuntu-latest

steps:
- ${{ each directory in parameters.directoryList }}:
    - task: CopyFilesOverSSH@0
      displayName: 'Securely copy files to the remote machine'
      inputs:
        sshEndpoint: 'ssh_10.20.21.22_service_connection'
        sourceFolder: '${{ directory }}/Components'
        contents: '**'
        targetFolder: '/home/user-dir/migration_all/${{ directory }}'

Upvotes: 0

Views: 1503

Answers (1)

Kevin Lu-MSFT
Kevin Lu-MSFT

Reputation: 35129

To solve this issue, you need to modify the value of the parameter.

Refer to my sample:

parameters:
- name: directoryList
  type: object
  default:
    - 'LOL-01'
    - 'LOL-02'
    - 'LOL-03'

pool:
  vmImage: ubuntu-latest

steps:
- ${{ each directory in parameters.directoryList }}:
    - script:  echo  ${{ directory }}

Result:

enter image description here

You need to remove the directoryList in the default value. When you add this value, the entire default value will be taken as a whole.

Upvotes: 1

Related Questions