Amazon web services 将AWS CodePipeline变量传递给操作

Amazon web services 将AWS CodePipeline变量传递给操作,amazon-web-services,amazon-cloudformation,aws-codepipeline,aws-codebuild,Amazon Web Services,Amazon Cloudformation,Aws Codepipeline,Aws Codebuild,我试图将CodePipeline变量#{CodePipeline PipelineExecutionId}传递给codeBuild操作和deploy操作 我理解,如中所述,此变量可随时用于所有操作 但是,我在语法方面遇到了困难,因为参数没有传递到动作中 我一直在使用以下代码: 对于构建操作: - Name: "Build-Docker-Container" Actions: - Name: "Build-Docker-Container

我试图将CodePipeline变量#{CodePipeline PipelineExecutionId}传递给codeBuild操作和deploy操作

我理解,如中所述,此变量可随时用于所有操作

但是,我在语法方面遇到了困难,因为参数没有传递到动作中

我一直在使用以下代码:

对于构建操作:

        - 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
对于部署操作:

        - 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


更新代码实际上很好;我只需要更新CloudFormation管道堆栈来应用它(我以为github webhook会触发它,但它只更新管道内的操作)

我可以确认您在部署操作中使用的语法是正确的:

                ParameterOverrides: !Sub |
                  {
                    "ProjectName": "${ProjectName}",
                    "ExecutionId": "#{codepipeline.PipelineExecutionId}"
                  }
我在与CloudFormation提供商的管道中验证了这一点。我还可以确认此操作是否按预期工作

如果编辑有问题的CFN操作,您可以在控制台中检查参数设置是否正确:


目前我无法验证构建操作,但从外观上看,它似乎也不错。

谢谢Marcin;我马上再检查一遍:)@JoelBarenco没问题。让我知道它是如何运行的。我可以确认它是有效的;当我推到github时,管道自动运行,而当我更改管道yml文件中的某些内容时,需要通过CFN进行更新,我仍然感到困惑。。。因此,我通过CFN更新了该文件,现在它确实按照预期工作。谢谢@JoelBarenco很高兴听到这个消息。如果答案有帮助,我们将不胜感激。