有条件地根据CloudFormation条件创建CodePipeline操作 - 无法正常工作

问题描述 投票:2回答:1

Conditionally create CodePipeline actions based on CloudFormation conditions

根据上面的链接fn :: if在aws codepipeline中工作但不幸的是它不适合我

以下是我的代码:

- !If
  - testCondition
  - Name: SwitchEnvironment
    ActionTypeId:
      Category: Build
      Owner: AWS
      Provider: CodeBuild
      Version: 1
    Configuration:
      ProjectName: !Ref SwitchDeployment
    InputArtifacts:
    - Name: Source
    OutputArtifacts:
    - Name: SwitchDeployment
    RunOrder: 1
  - !Ref AWS::NoValue

如果我将此条件设置为false,则cloudformation将显示“Property Actions不能为空”。

amazon-web-services amazon-cloudformation
1个回答
1
投票

当我将!IF语句放在Actions部分中时,我遇到了相同的错误消息。根据AWS文档(link to AWS docs),在管道阶段至少需要执行1个操作。因此,如果condition的计算结果为false,则会有0个操作并导致该错误。以下为我工作(适合您的例子):

- !If
  - testCondition
  - Name: SwitchEnvironment
    Actions:
      - Name: NameOfYourConditionalAction
        ActionTypeId:
          Category: Build
          Owner: AWS
          Provider: CodeBuild
          Version: 1
        Configuration:
          ProjectName: !Ref SwitchDeployment
        InputArtifacts:
          - Name: Source
        OutputArtifacts:
          - Name: SwitchDeployment
        RunOrder: 1
  - !Ref AWS::NoValue
© www.soinside.com 2019 - 2024. All rights reserved.