Search code examples
azure-devopsazure-pipelinesazure-pipelines-yaml

How can I solve indentation problem in Azure yaml pipeline?


How can I solve indentation problem in stages?

/devops/azure-pipelines.yml (Line: 6, Col: 16): A sequence was not expected.

Line 6 means "webJobNames: ['A', 'B', 'C', 'D', 'E', 'F']" here. What is the issue?

trigger:
  - main
variables:
  buildPlatform: Any CPU
  buildConfiguration: Release
  webJobNames: ['A', 'B', 'C', 'D', 'E', 'F']
stages:
  - stage: Build
    displayName: Build stage
    pool:
      vmImage: windows-latest
    jobs:
      - job: XJob
        displayName: Build X Job
        steps:
          - checkout: self
            displayName: checkout
  - stage: Deploy
    displayName: Deploy stage
    pool:
      vmImage: windows-latest
    jobs:
      - job: DeployWebJobs
        displayName: Deploy Web Jobs
        steps:
          - '${{ each webJobName in variables.webJobNames }}':
          - task: PowerShell@2
            displayName: 'Deploy ${{ webJobName }} Web Job'
            inputs:
                  targetType: inline
                  script: |
                    Write-Host "Deploying ${{ webJobName }} Web Job"
                    # Add deployment steps specific to each web job here

This is working below but I want to convert below to above yaml

trigger:
  - main

variables:
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'
  webJobNames: 'A,B,C,D,E,F'

stages:
  - stage: Deploy
    displayName: 'Deploy stage'
    jobs:
      - job: XJobs
        displayName: 'Deploy X Jobs'
        steps:
          - ${{ each webJobName in split(variables.webJobNames, ',') }}:
            - task: PowerShell@2
              displayName: "Deploy ${{ webJobName }} Web Job"
              inputs:
                targetType: "inline"
                script: |
                  Write-Host "Deploying ${{ webJobName }} Web Job"
                  # Add deployment steps specific to each web job here


Solution

  • The problem is that variables must be strings. There is no support for typed variables. Parameters, however, can be typed.

    You'll also find another syntax error further down, - '${{ each webJobName in variables.webJobNames }}': should be - ${{ each webJobName in variables.webJobNames }}: