Trying to create multi-stage YAML for Azure DevOps - Getting Unknown Validation Errors

Viewed 17

In attempting to create an Azure DevOps pipeline using a multi-stage YAML format, I ran into a few errors during validation that I could not quite work out. I am not sure why, but I am getting errors on line 18, 101 and 105, particularly the "stage" and second "jobs". I have tried messing around with indentation but haven't had any luck. Am I perhaps implementing multi-stage wrong? I feel like its glaringly obvious but I cannot see it.

trigger:
- main

pool:
  name: Azure Pipelines
steps:
- script: |
   sudo apt install tree
   tree
  displayName: 'Command Line Script'

#Build Portion
- stage: Build
  displayName: Build stage
  jobs:
  - job: Job_1
    displayName: Agent job 1
    pool:
      vmImage: ubuntu-20.04
    steps:
    - checkout: self
    - task: CmdLine@2
      displayName: Command Line Script
      inputs:
        script: >-
          sudo apt install tree

          tree
    - task: Docker@0
      displayName: 'Build $(RELEASE_NAME) image'
      inputs:
        azureSubscription: '$(AZ_ACR_SUBSCRIPTION)'
        azureContainerRegistry: '{"loginServer":"$(ACR_LOGINSERVER)", "id" : "$(ACR_ID)"}'
        dockerFile: Dockerfile
        buildArguments: '--progress=plain'

    - task: Docker@0
      displayName: 'Push a $(RELEASE_NAME) image'
      inputs:
        azureSubscription: '$(AZ_ACR_SUBSCRIPTION)'
        azureContainerRegistry: '{"loginServer":"$(ACR_LOGINSERVER)", "id" : "$(ACR_ID)"}'
        action: 'Push an image'

    - task: HelmInstaller@0
      displayName: 'Install Helm 2.9.1'
      inputs:
        helmVersion: 2.9.1
        kubectlVersion: 1.10.3
        checkLatestKubectl: false

    - script: |
        echo Write your commands here
        echo Hello world
        echo "PredefVar: Build Repository Name:"
        echo $(Build.Repository.Name)
        echo "PredefVar: Build ID:"
        echo $(Build.BuildId)
        echo "PredefVar: Build artifact staging dir:"
        echo $(Build.ArtifactStagingDirectory)
        displayName: 'Command Line Script'

    - task: HelmDeploy@0
      displayName: 'helm init --client-only'
      inputs:
        azureSubscription: '$(AZ_SUBSCRIPTION)'
        azureResourceGroup: '$(RESOURCE_GROUP)'
        kubernetesCluster: '$(AKS_CLUSTER_NAME)'
        namespace: $(PROJECT_NAMESPACE)
        command: init
        upgradeTiller: false
        arguments: '--client-only'
      enabled: false

    - task: HelmDeploy@0
      displayName: 'helm package'
      inputs:
        command: package
        chartPath: helm
        chartVersion: '$(Build.BuildId)'
        save: false

    - task: PublishBuildArtifacts@1
      displayName: 'Publish Pipeline Artifact'
      inputs:
        ArtifactName: '$(ARTIFACT_NAME)'

    - task: PublishBuildArtifacts@1
      displayName: 'Publish Artifacts: drop copy'
      enabled: false

    - script: |
        tree
      displayName: 'Check Filesystem'

#Release Portion
- stage: Dev
  displayName: Dev Release stage
  dependsOn: Build
  condition: succeeded('Build')
  jobs:
  - deployment: Dev
    displayName: Dev
    environment: 'development'
    pool:
      vmImage: $(vmImageName)
    strategy:
      runOnce:
        deploy:
          steps:
          - task: HelmDeploy@0
            displayName: 'helm upgrade'
            inputs:
              azureSubscription: '$(AZ_SUBSCRIPTION)'
              azureResourceGroup: '$(RESOURCE_GROUP)'
              kubernetesCluster: '$(AKS_CLUSTER_NAME)'
              namespace: '$(PROJECT_NAME)'
              command: upgrade
              chartType: FilePath
              chartPath: '$(System.DefaultWorkingDirectory)/$(Build.Repository.Name)/$(ARTIFACT_NAME)/$(RELEASE_NAME)-*.tgz'
              chartVersion: '$(Build.BuildId)'
              releaseName: '$(RELEASE_NAME)'
              recreate: true
              resetValues: true
              force: true
              arguments: '--set image.tag=$(Build.BuildId)'

1 Answers

I discovered two things. One issue was the lack of "stages:" line, however after applying this line, I received errors on the stages line which perplexed me for a while. The problem was resolved after moving the command line script step within the first stage labeled "build" Apparently you cannot run tasks outside of stages when applying stages format to a pipeline YML.

Related