程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了使用 Azure DevOps 管道将标签应用到 CFN 堆栈 - 列表?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决使用 Azure DevOps 管道将标签应用到 CFN 堆栈 - 列表??

开发过程中遇到使用 Azure DevOps 管道将标签应用到 CFN 堆栈 - 列表?的问题如何解决?下面主要结合日常开发的经验,给出你关于使用 Azure DevOps 管道将标签应用到 CFN 堆栈 - 列表?的解决方法建议,希望对你解决使用 Azure DevOps 管道将标签应用到 CFN 堆栈 - 列表?有所启发或帮助;

根据我前几天的问题...

Passing an object into a template in Azure DevOps pipeline

我现在面临的问题是,我尝试使用管道将标签应用于从 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,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)

当我运行它时,我得到第一个标签 Component=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

大佬总结

以上是大佬教程为你收集整理的使用 Azure DevOps 管道将标签应用到 CFN 堆栈 - 列表?全部内容,希望文章能够帮你解决使用 Azure DevOps 管道将标签应用到 CFN 堆栈 - 列表?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。