Home > Enterprise >  AWS Cloudformation Environment Variables for Codepipline Build Step
AWS Cloudformation Environment Variables for Codepipline Build Step

Time:12-10

I've been trying to add a simple environment variable to a YAML cloudformation template. I pass in to the template as a parameter when creating whether it is "production" or "staging", and want to pass that on in the "Build" section of my codepipline.

        - Name: "Build"
          Actions:
            - Name: "Build"
              ActionTypeId:
                Category: "Build"
                Owner: "AWS"
                Provider: "CodeBuild"
                Version: "1"
              Configuration:
                ProjectName: !Ref CodeBuildProject
                # EnvironmentVariables:
                #   - Name: "CURRENT_ENVIRONMENT"
                #     Type: PLAINTEXT
                #     Value: !Ref CodeEnvironment
                # EnvironmentVariables: !Sub | 
                #   "{\"name\":\"CURRENT_ENVIRONMENT\", \"type\": \"PLAINTEXT\" \"value\": \"${CodeEnvironment}\"}"
                EnvironmentVariables: "{\"name\":\"CURRENT_ENVIRONMENT\", \"type\": \"PLAINTEXT\" \"value\": \"${CodeEnvironment}\"}"
              InputArtifacts:
                - Name: "SourceArtifact"
              OutputArtifacts:
                - Name: "secondary_artifact_name_1"
                - Name: "secondary_artifact_name_2"
              Region: !Ref AWS::Region
              Namespace: "BuildVariables"
              RunOrder: 1

`

I've tried a few different ways of passing in "EnvironmentVariables", but keep getting this error:

The configuration for the action 'Build' configurationKey 'EnvironmentVariables' does not match the expected format. The expected format is JSON array adhering to the following format: [{"name": "string", "type": "string", "value": "string"}] (Service: AWSCodePipeline; Status Code: 400; Error Code: InvalidActionDeclarationException; Request ID: fe7b8f6b-5410-48d2-b18f-f9377d1898cb; Proxy: null)

I've seen ways to do this in a json template, but having trouble doing it in a yaml template

CodePudding user response:

The EnvironmentVariables should be JSON array, not a plain map. So it should be:

EnvironmentVariables: "[{\"name\":\"CURRENT_ENVIRONMENT\", \"type\": \"PLAINTEXT\" \"value\": \"${CodeEnvironment}\"}]"
  • Related