admin管理员组文章数量:1126345
I am trying to iterate over the stages array, however I get the following error when running the pipeline:
(Line: 36, Col: 15): Unable to convert from Array to String. Value: Array
parameters:
- name: stages
type: object
default: [0,1,100]
- stage: Validate_Stages
jobs:
- job: Validate_Stages_Job
steps:
- script: |
echo "Validating stages"
for stage in "${{ parameters.stages }}"; do
if [ $stage -lt 0 ] || [ $stage -gt 100 ]; then
echo "Invalid stage value $stage. Stage values must be between 0 and 100"
exit 1
fi
done
- ${{ each stage in parameters.stages }}:
- stage: Stage_${{ stage }}
jobs:
.
.
.
I am trying to iterate over the stages array, however I get the following error when running the pipeline:
(Line: 36, Col: 15): Unable to convert from Array to String. Value: Array
parameters:
- name: stages
type: object
default: [0,1,100]
- stage: Validate_Stages
jobs:
- job: Validate_Stages_Job
steps:
- script: |
echo "Validating stages"
for stage in "${{ parameters.stages }}"; do
if [ $stage -lt 0 ] || [ $stage -gt 100 ]; then
echo "Invalid stage value $stage. Stage values must be between 0 and 100"
exit 1
fi
done
- ${{ each stage in parameters.stages }}:
- stage: Stage_${{ stage }}
jobs:
.
.
.
Share
Improve this question
edited 2 days ago
JS noob
asked Jan 8 at 23:50
JS noobJS noob
4876 silver badges20 bronze badges
4
|
1 Answer
Reset to default 0If you need a string from your array, you can try join: https://learn.microsoft.com/en-us/azure/devops/pipelines/process/expressions?view=azure-devops#join
as an example...
parameters:
- name: stages
type: object
default: [0,1,100]
variables:
myvar.A: ${{ join(' ',parameters.stages) }}
stages:
- stage: Validate_Stages
jobs:
- job: Validate_Stages_Job
steps:
- script: |
stages=($(myvar.A))
echo "Validating stages $(myvar.A)"
for stage in "${stages[@]}"; do
if [ $stage -lt 0 ] || [ $stage -gt 100 ]; then
echo "Invalid stage value $stage. Stage values must be between 0 and 100"
exit 1
fi
done
本文标签:
版权声明:本文标题:azure devops - In my ado pipeline how do I iterate over a object type parameter that is an array - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736682397a1947487.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
[0,1,100]
verbatim to a bash script, it should be defined as a string. You're not doing anything with it to iterate over it in the pipeline itself. As it stands, you're trying to take an object and treat it as a string, which Azure Pipelines can't do. Remember, an object might be a much more complex YAML object that doesn't really map to a string in any meaningful way. – Daniel Mann Commented Jan 9 at 5:11${{ each stage in parameters.stages }}
to generate stage names the pipeline will fail if there are any repeated elements in the array (e.g.55
) because all stages must have distinct names. – Rui Jarimba Commented 2 days ago