根据CloudFormation条件有条件地创建CodePipeline操作-不起作用

时间:2018-12-12 10:12:10

标签: amazon-web-services amazon-cloudformation

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会显示“属性操作不能为空”。

1 个答案:

答案 0 :(得分:1)

将!IF语句放入“动作”部分时,我遇到了相同的错误消息。根据AWS文档(link to AWS docs),在管道阶段至少需要执行1个操作。因此,如果条件评估为假,则将有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