JohnWick
JohnWick

Reputation: 21

Conditionally create CodePipeline actions based on CloudFormation conditions - not working

Conditionally create CodePipeline actions based on CloudFormation conditions

As per the above link fn::if works within aws codepipeline but unfortunately its not working for me

Below is my code:

- !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

If I set this condition false, the cloudformation says "Property Actions cannot be empty".

Upvotes: 2

Views: 450

Answers (1)

michael
michael

Reputation: 11

I ran into the same error message when i put the !IF statement inside the Actions section. According to AWS documentation (link to AWS docs) a minimum of 1 action is required in a pipeline stage. So if condition evaluates to false there will be 0 actions and leads to that error. The following worked for me (adapted to your example):

- !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

Upvotes: 1

Related Questions