I have quite peculiar case for azure devops pipeline.
Firstly, I have this main pipeline.yaml
:
trigger:
- development
pool:
name: '$(dds-ubuntu-agent)'
name: $(date:MM.dd.yyyy)-$(SERVICE_NAME)-$(Build.SourceBranchName)-$(Build.BuildId)
stages:
- template: ./test-stages.yaml
Then there is test-stages.yaml
, where I need to add template for certain stage multiple times, just with different parameters (deployment to multiple environments):
stages:
- template: ./test-stage.yaml
parameters:
test: 'asdf'
- template: ./test-stage.yaml
parameters:
test: 'qwer'
And test-stage.yaml
defines the stage:
parameters:
- name: test
type: String
stages:
- stage: ${{ parameters.test }}
displayName: ${{ parameters.test }}
jobs:
- job: ${{ parameters.test }}
steps:
- script: echo ${{ parameters.test}}
When I commit this to the repository and create pipeline in Azure DevOps, it fails to run with error
/test-stage.yaml (Line: 3, Col: 9): Unexpected value 'String'
I do not quite see where the error is, I double-checked the indentation and job/stage definitions and it all seems to be correct. I am almost convinced that there is some limitation on how stages can be nested - if I am wrong, please correct me. But I do not have any problem with the pipeline when I unwrap the nested template structure into single template.
Is it possible to nest the stages like this or no?
/test-stage.yaml (Line: 3, Col: 9): Unexpected value 'String'
I can reproduce the same issue when using the same YAML sample.
The cause of the issue can be that the value of parameters type filed needs to be lowercase.
To solve this issue, you need to change from String to string in test-stage.yaml file.
For example:
parameters:
- name: test
type: string
stages:
- stage: ${{ parameters.test }}
displayName: ${{ parameters.test }}
jobs:
- job: ${{ parameters.test }}
steps:
- script: echo ${{ parameters.test}}
For more detailed info, you can refer to this doc: Parameters types