尝试使用数组执行任务时发生Azure DevOps错误



我有一个AZD部署模板,如下所示。我正在尝试执行一项任务(Kubernetes@1)多次循环参数中定义的数组。

parameters:
- name: env
- name: serviceConnection
- name: 'serviceNames'
type: object
default:
- audit
- export
- admin
jobs:
- deployment: Deployment
displayName: Deploy to ${{ parameters.env }}
environment: ${{ parameters.env }}
pool: on-prem-pool
variables:
- template: azure-deploy-vars.yaml
parameters:
env: ${{ parameters.env }}
timeoutInMinutes: 10
strategy:
runOnce:
deploy:
steps:
- script: |
echo "Prepare to deploy config for ${{ parameters.serviceNames}}. clean workspace"
ls -la
cd ..
ls -la
rm -rf config
rm -rf devops
rm -rf TestResults
rm -rf helm
rm -f config.sh
rm -f *.properties
displayName: 'Clean Workspace'
- checkout: config
path: config
- ${{ each service in parameters.serviceNames }}:
- task: Kubernetes@1
displayName: Deploy Config
inputs:
connectionType: Kubernetes Service Connection
kubernetesServiceEndpoint: '${{ parameters.serviceConnection }}'
namespace: '$(PROJECT_NAMESPACE)'
configMapName: '${{ service }}'
forceUpdateConfigMap: true
useConfigMapFile: true
configMapFile: '$(Agent.BuildDirectory)/config/${{ service }}/${{ parameters.env }}/application-${{ parameters.env }}.properties'

但当我尝试运行管道时,我会遇到这个错误。如果我的模板有错误,有人能告诉我吗?

错误:

/ci/azure-deploy.tpl.yaml: (Line: 41, Col: 11, Idx: 1048) - (Line: 41, Col: 12, Idx: 1049): While parsing a block mapping, did not find expected key.

您需要缩进行

- ${{ each service in parameters.serviceNames }}:

以使其匹配其上方的- script:- checkout:行,然后也增加后续行的缩进。

已更正的模板:

parameters:
- name: env
- name: serviceConnection
- name: 'serviceNames'
type: object
default:
- audit
- export
- admin
jobs:
- deployment: Deployment
displayName: Deploy to ${{ parameters.env }}
environment: ${{ parameters.env }}
pool: on-prem-pool
variables:
- template: azure-deploy-vars.yaml
parameters:
env: ${{ parameters.env }}
timeoutInMinutes: 10
strategy:
runOnce:
deploy:
steps:
- script: |
echo "Prepare to deploy config for ${{ parameters.serviceNames}}. clean workspace"
ls -la
cd ..
ls -la
rm -rf config
rm -rf devops
rm -rf TestResults
rm -rf helm
rm -f config.sh
rm -f *.properties
displayName: 'Clean Workspace'
- checkout: config
path: config
- ${{ each service in parameters.serviceNames }}:
- task: Kubernetes@1
displayName: Deploy Config
inputs:
connectionType: Kubernetes Service Connection
kubernetesServiceEndpoint: '${{ parameters.serviceConnection }}'
namespace: '$(PROJECT_NAMESPACE)'
configMapName: '${{ service }}'
forceUpdateConfigMap: true
useConfigMapFile: true
configMapFile: '$(Agent.BuildDirectory)/config/${{ service }}/${{ parameters.env }}/application-${{ parameters.env }}.properties'

相关内容

  • 没有找到相关文章

最新更新