使用Azure DevOps管道列表应用标签到CFN堆栈?



根据我前几天的问题…

在Azure DevOps管道中传递对象到模板

我现在面临的问题是,我正试图使用管道将标签应用到从Azure DevOps管道创建的AWS CloudFormation堆栈。

这是管道(它的一部分):-

# azure-pipelines.yml
parameters:
- name: stackparams
type: object
default:
- displayname: AWS Test User Account
awscredentials: TESTAWS-BuildUser
templatefile: ./Test/TestApp/ConsoleSwitchRolesGroupsPolicies.yml
templateparametersfile: ./Test/TestApp/demoparams.json
tags:
- tag1
- tag2
- Managed=Cloudformation
stages:
- stage: ProdDeploy  # name of the stage (A-Z, a-z, 0-9, and underscore)
displayName: Production Deploy  # friendly name to display in the UI
jobs:
- deployment: DeveloperRoles   # name of the deployment job (A-Z, a-z, 0-9, and underscore)
displayName: Manage Developer Roles using Cloudformation  # friendly name to display in the UI
pool:
vmImage: 'ubuntu-latest'
environment: aws-test-appaccount-structure  # target environment name and optionally a resource name to record the deployment history; format: <environment-name>.<resource-name>
strategy:
runOnce:    #rolling, canary are the other strategies that are supported
deploy:
steps:
- template : ./Templates/CfnUpdateStack/CfnUpdateStack.yml
parameters:
stackparams: ${{ parameters.stackparams }}
runRolesGroupsPolicies: ${{ parameters.runRolesGroupsPolicies }}

模板如下:-

# CfnUpdateStack.yml
parameters:
- name: stackparams
type: object
- name: runRolesGroupsPolicies
type: boolean
steps:
- ${{ each stackparam in parameters.stackparams }}:
- task: CloudFormationCreateOrUpdateStack@1
displayName: ${{ stackparam.displayname }}
inputs:
awsCredentials: ${{ stackparam.awscredentials }}
regionName: 'eu-west-1'
stackName: 'ConsoleSwitchRolesGroupsPolicies'
templateSource: 'file'
templateFile: ${{ stackparam.templatefile }}
templateParametersFile: ${{ stackparam.templateparametersfile }}
tags: |
Component=RoleUserAccess
${{ stackparam.tags }}
condition: eq('${{ parameters.runRolesGroupsPolicies }}', true)

当我运行这个我只有得到第一个标签组件=RoleUserAccess。我已经设法让它工作,但使用这种可怕的丑陋的方法使用一个变量(不是参数),并在每个标记之间放一个空白行。但它确实有效!

Versions
variables:
- name: tags
value: "tag1
tag2
Managed=Cloudformation"

每个资源大约有20个标签,所以它变得相当混乱。我把它删节了,使问题更容易读懂。

有什么建议吗?

谢谢,

似乎你正试图将数组(标签)添加到数组(stackparams),我认为这是不正确的。您可以尝试以下语法:

# CfnUpdateStack.yml

parameters:
- name: 'tags'
type: object
default: {}
- name: 'displayname'
type: string
default: ''
- name: 'awscredentials'
type: string
default: ''
- name: 'templatefile'
type: string
default: ''
- name: 'templateparametersfile'
type: string
default: ''
steps:



# azure-pipelines.yml


- template: CfnUpdateStack.yml
parameters:
tags: 
- tag1
- tag2
- Managed=Cloudformation  
displayname: AWS Test User Account
awscredentials: TESTAWS-BuildUser
templatefile: ./Test/TestApp/ConsoleSwitchRolesGroupsPolicies.yml
templateparametersfile: ./Test/TestApp/demoparams.json

- template: CfnUpdateStack.yml
parameters:
tags: 
- tag1
- tag2
- Managed=Cloudformation  
displayname: AWS Test User Account2
awscredentials: TESTAWS-BuildUser2
templatefile: ./Test/TestApp/ConsoleSwitchRolesGroupsPolicies2.yml
templateparametersfile: ./Test/TestApp/demoparams2.json

最新更新