I'm trying to get a list of directories and then pass that array to an azure pipeline template. Here's the code for getting the array names:
- script: |
cd $(Build.StagingDirectory)
directoryList=( $(ls -d */ | sed 's#/##') ) # sed gets rid of the trailing slash
echo $directoryList
echo "##vso[task.setvariable variable=directoryList]$directoryList"
# Archive all directories in staging directory created by sam build
- template: zip-template.yml
parameters:
directories:
- $(directoryList)
One thing I noticed is that echo $(directoryList) only outputs the first entry. When I try to pass this to the template it only performs 1 iteration which makes me think I'm not creating the array correctly. Here's the azure pipeline template that should receive the list of directory names:
parameters:
- name: "directories"
type: object
default: {}
steps:
- ${{ each dir in parameters.directories }}:
- task: ArchiveFiles@2
displayName: "Zip ${{ dir }}"
inputs:
rootFolderOrFile: '$(Build.StagingDirectory)/${{dir}}'
includeRootFolder: false
archiveType: 'zip'
archiveFile: '$(Build.StagingDirectory)/${{dir}}/package.zip'
replaceExistingArchive: true
Another odd outcome I observed is that the displayName outputs "Zip ($directoryList)" when I run the pipeline. What can I do to get the list of directories an pass that to the template to iterate through and run the zip task multiple times?
