0

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

1 Answer 1

0

It seems that the expression $[ dependencies.first.outputs['FetchRepositoriesTask.csvRepositoriesUrl'] ] doesn't get evaluated when using the Template expression syntax. As an alternative, you can use PowerShell Split

- powershell: | 
    "$(repositories)" -split "," | ForEach {
      "Repo: $_"
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.