Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Trouble with Azure Pipelines in defining stages and branches

Why can’t I do this:

azure-pipeline.yml: extends build-and-deploy.yml@demo

...

parameters:
- name: allowDevDeployment
  displayName: "Allow this build to be deployed to DEV"
  type: boolean
  default: false

- name: selectDeploymentType
  displayName: Select deployment type
  type: string
  default: 0
  values:
    - 0 # (Standard/regular deployment)
    - 1 #(Single branch; master deploys to  DEV -> DEVTEST -> STAGE -> PROD)
    - 2 # (develop to DEV -> Auto PR to master -> DEVTEST -> STAGE -> PROD)


extends:
  template: templates/build-and-deploy.yml@demo
  parameters:
    allowDevDeployment: ${{ parameters.allowDevDeployment }}
    deploymentType: ${{ parameters.selectDeploymentType}}
    ...

In templates/build-and-deploy.yml: Based on what’s selected during pipeline runtime, either 0.yml, 1.yml or 2.yml is called (up till this point it works because I have a pwsh step (before it calls the template) that write-host the parameter that’s selected at runtime, and it outputs the right parameter. The step isn’t included here)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

parameters:
  ...
- name: deploymentType
  type: string
  default: none

steps:
  - ${{ if eq(parameters.deploymentType, 0)}}:
    - template: deploymentTypes/0.yml
      parameters:
        allowDevDeployment: ${{ parameters.allowDevDeployment }}
        ...
  - ${{ if eq(parameters.deploymentType, 1)}}:
    - template: deploymentTypes/1.yml
      parameters:
        allowDevDeployment: ${{ parameters.allowDevDeployment }}
        ...
  - ${{ if eq(parameters.deploymentType, 2)}}:
    - template: deploymentTypes/2.yml
      parameters:
        allowDevDeployment: ${{ parameters.allowDevDeployment }}
        ...

and in deploymentTypes/0.yml (or 2.yml or 3.yml): At this point, I get an error that reads "/templates/deploymentTypes/0.yml@demo (Line: 184, Col: 1): Unexpected value ‘stages’"

enter image description here

This file (0.yml or 2.yml or 3.yml) essentially defines what stages must run depending on what branch is built or the pipeline is run from.

parameters:
...
- name: allowDevDeployment
  type: boolean
  default: false
    
stages:
- ${{ if gt(length(parameters.buildJobs), 0) }}:
  - stage: Build
    jobs:
    - ${{ each job in parameters.buildJobs }}:
      - ${{ if startsWith(job.pool.vmImage, 'ubuntu') }}:
        - job: ${{ job.job }}
          pool: ${{ job.pool }}
          ${{ if job.condition }}:
            condition: ${{ job.condition }}
            ...
# Develop, Nightly or Support Branch
- ${{ if or(in(variables['Build.SourceBranchName'], 'develop', 'nightly'), contains(variables['Build.SourceBranch'], '/support/'), eq(parameters.allowDevDeployment, true)) }}:
  - ${{ if gt(length(parameters.devJobs), 0) }}:
    - stage: Dev
      ...

# Develop or Support Branch
- ${{ if or(eq(variables['Build.SourceBranchName'], 'develop'), contains(variables['Build.SourceBranch'], '/support/')) }}:
  - ${{ if gt(length(parameters.devTestJobs), 0) }}:
    - stage: DevTest
      ${{ if ne(parameters.devTestStageLabel, 'none') }}:
        displayName: ${{ parameters.devTestStageLabel }}
        ...

>Solution :

I can reproduce the same error with your yaml sample.

enter image description here

The error is caused by the steps parameter in templates/build-and-deploy.yml, you should change it to stages since it invokes stage level template in 0.yml,1.yml…

templates/build-and-deploy.yml

parameters:
- name: allowDevDeployment
  type: boolean
  default: false

- name: deploymentType
  type: string
  default: none
 
stages:                  # change steps to stages here
  - ${{ if eq(parameters.deploymentType, 0)}}:
    - template: deploymentTypes/0.yml
      parameters:
        allowDevDeployment: ${{ parameters.allowDevDeployment }}

  - ${{ if eq(parameters.deploymentType, 1)}}:
    - template: deploymentTypes/1.yml
      parameters:
        allowDevDeployment: ${{ parameters.allowDevDeployment }}

  - ${{ if eq(parameters.deploymentType, 2)}}:
    - template: deploymentTypes/2.yml
      parameters:
        allowDevDeployment: ${{ parameters.allowDevDeployment }}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading