I have to create a pipeline and execute a series of tasks per each of my repositories.
So I created a job that fetch the repositories using the rest api https://dev.azure.com/{organization}/{project}/_apis/git/repositories?api-version=7.0 and then setting an output variable with all the urls in a csv format.
In another job I take this csv and do an split by an iterate over it like this sample https://learn.microsoft.com/en-us/azure/devops/pipelines/process/expressions?view=azure-devops#split
And the each expression instead of evaluate the expression is taking the expression itself as an string.
trigger: none
pool:
vmImage: windows-2022
stages:
- stage:
jobs:
- job: FetchRepositoriesJob
displayName: Fetch repositories
workspace:
clean: all
steps:
- checkout: none
- task: PowerShell@2
name: FetchRepositoriesTask
displayName: Fetch repositories
inputs:
targetType: 'inline'
script: |
# ... Code to fetch repositories and create a csv of the urls was omitted for brevety
$csvRepositoriesUrl="https://dev.azure.com/myorg/myproject/_git/repo1,https://dev.azure.com/myorg/myproject/_git/repo2"
Write-Host "##vso[task.setvariable variable=csvRepositoriesUrl;isOutput=true]$csvRepositoriesUrl"
- job: MyOtherJob
dependsOn: FetchRepositoriesJob
condition: succeeded('FetchRepositoriesJob')
workspace:
clean: all
variables:
- name: repositories
value: $[ dependencies.FetchRepositoriesJob.outputs['FetchRepositoriesTask.csvRepositoriesUrl'] ]
steps:
- checkout: none
- powershell: Write-Host $(repositories) # this task print "https://dev.azure.com/myorg/myproject/_git/repo1,https://dev.azure.com/myorg/myproject/_git/repo2"
- ${{ each repository in split(variables.repositories, ',')}}:
- powershell: Write-Host ${{ repository }} # but this task print: "$[ dependencies.FetchRepositoriesJob.outputs['FetchRepositoriesTask.csvRepositoriesUrl'] ]"
# here I would like to execute a series of task per each repository