title: using for-loop in azure pipeline jobs
body: <p>I'm gonna use a for-loop which scans the files (value-f1.yaml, values-f2.yaml,...) in a folder and each time use a filename as a varibale and run the job in Azure pipeline job to deploy the helmchart based on that values file. The folder is located in the GitHub repository. So I'm thinking of something like this:</p>
  
  <p>pipeline.yaml</p>
  
  <pre><code> stages:
    - stage: Deploy
      variables:
        azureResourceGroup: ''
        kubernetesCluster: ''
        subdomain: ''
      jobs:
      ${{ each filename in /myfolder/*.yaml}}:
         valueFile: $filename 
         - template: Templates/deploy-helmchart.yaml@pipelinetemplates    
  </code></pre>
  
  <p>deploy-helmchart.yaml</p>
  
  <pre><code> jobs:
      - job: Deploy
        pool:
          vmImage: 'ubuntu-latest'
        steps:
        - task: HelmInstaller@1
          displayName: 'Installing Helm'
          inputs:
            helmVersionToInstall: '2.15.1'
          condition: and(succeeded(), startsWith(variables['build.sourceBranch'], 'refs/tags/v'))  
  
        - task: HelmDeploy@0
          displayName: 'Initializing Helm'
          inputs:
            connectionType: 'Azure Resource Manager'
            azureSubscription: $(azureSubscription)
            azureResourceGroup: $(azureResourceGroup)
            kubernetesCluster: $(kubernetesCluster)
            command: 'init'
          condition: and(succeeded(), startsWith(variables['build.sourceBranch'], 'refs/tags/v'))  
  
        - task: PowerShell@2
          displayName: 'Fetching GitTag'
          inputs:
            targetType: 'inline'
            script: |
              # Write your PowerShell commands here.
              Write-Host "Fetching the latest GitTag"
              $gt = git describe --abbrev=0
              Write-Host "##vso[task.setvariable variable=gittag]$gt"
          condition: and(succeeded(), startsWith(variables['build.sourceBranch'], 'refs/tags/v'))    
  
  
        - task: Bash@3
          displayName: 'Fetching repo-tag'
          inputs:
            targetType: 'inline'
            script: |
              echo GitTag=$(gittag)
              echo BuildID=$(Build.BuildId)
              echo SourceBranchName=$(Build.SourceBranchName)
              echo ClusterName= $(kubernetesCluster)
  
        - task: HelmDeploy@0
          displayName: 'Upgrading helmchart'
          inputs:
            connectionType: 'Azure Resource Manager'
            azureSubscription: $(azureSubscription)
            azureResourceGroup: $(azureResourceGroup)
            kubernetesCluster: $(kubernetesCluster)
            command: 'upgrade'
            chartType: 'FilePath'
            chartPath: $(chartPath)
            install: true
            releaseName: $(releaseName)
            valueFile: $(valueFile)
            arguments: '--set image.tag=$(gittag) --set subdomain=$(subdomain)'
          condition: and(succeeded(), startsWith(variables['build.sourceBranch'], 'refs/tags/v'))  
  </code></pre>
  
  <p>Another thing is that if the jobs can get access to the GitHub repo by default or do I need to do something in the job level?</p>
  
  <p>Besides how can I use for-loop in the job for this case? </p>
  
  <p>Any help would be appreciated.</p>
  
  <p>Updated after getting comments from @Leo</p>
  
  <p>Here is a PowerShell task that I added in deploy-helmchart.yaml for fetching the files from a folder in GitHub.</p>
  
  <pre><code> - task: PowerShell@2
     displayName: 'Fetching Files'
     inputs:
       targetType: 'inline'
       script: |
         Write-Host "Fetching values files"
         cd myfolder
         $a=git ls-files
         foreach ($i in $a) {
            Write-Host "##vso[task.setvariable variable=filename]$i"
            Write-Host "printing"$i
         }
  </code></pre>
  
  <p>Now the question is how can I run the task: HelmDeploy@0 for each files using parameters?</p>