Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass AWS CodePipeline variable to actions

I'm trying to pass the CodePipeline variable #{codepipeline PipelineExecutionId} to both the codeBuild action and then a deploy action.

I understand this variable is readily available to all actions as explained in AWS docs.

I'm however having a difficulty with the syntax as the parameters is not passed thru into the actions.

I've been using the following code:

For the build actions:

        - Name: "Build-Docker-Container"
          Actions:
            - Name: "Build-Docker-Container"
              ActionTypeId:
                Category: Build
                Owner: AWS
                Provider: CodeBuild
                Version: "1"
              Configuration:
                ProjectName: !Sub ${ProjectName}-build-${BranchName}
                EnvironmentVariables:
                  - Name: IMAGE_TAG
                    Type: PLAINTEXT
                    Value: "#{codepipeline.PipelineExecutionId}"
              InputArtifacts:
                - Name: !Ref ProjectName
              RunOrder: 3

and for the deploy action:

        - Name: "Deploy-Services"
          Actions:
            - Name: "Deploy-Services"
              ActionTypeId:
                Category: Deploy
                Owner: AWS
                Provider: CloudFormation
                Version: "1"
              Configuration:
                ActionMode: CREATE_UPDATE
                StackName: !Sub "${ProjectName}-services-${BranchName}"
                TemplatePath: !Sub "${ProjectName}::aws/03-services.yml"
                Capabilities: "CAPABILITY_NAMED_IAM"
                RoleArn: !GetAtt DeployRole.Arn
                ParameterOverrides: !Sub |
                  {
                    "ProjectName": "${ProjectName}",
                    "ExecutionId": "#{codepipeline.PipelineExecutionId}"
                  }
              InputArtifacts:
                - Name: !Ref ProjectName
                - Name: InfrastructureOutput
              RunOrder: 4

UPDATE The code was actually good; I just needed to update the CloudFormation pipeline stack to apply it (I thought the github webhook would trigger this, but it only update the actions inside the pipeline)

like image 964
Joel Barenco Avatar asked Jun 09 '26 22:06

Joel Barenco


1 Answers

I can confirm that the syntax you've used in the deploy action is correct:

                ParameterOverrides: !Sub |
                  {
                    "ProjectName": "${ProjectName}",
                    "ExecutionId": "#{codepipeline.PipelineExecutionId}"
                  }

I verified that on my Pipeline with CloudFormation provider. I can also confirm that this works as expected.

You can check in console if you edit the CFN action's in question, that the parameters are correctly set:

enter image description here

For now I can't verify build action, but by the look of it, it also seems fine.

like image 144
Marcin Avatar answered Jun 12 '26 12:06

Marcin