将 AWS CodePipeline 变量传递给 actions。

问题描述 投票:0回答:1

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

我知道这个变量很容易被所有的操作所使用,就像在 AWS文档.

然而,我在语法上遇到了一个困难,因为参数没有传递到动作中。

我一直在使用下面的代码。

对于构建动作,

        - 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

UPDATE 这段代码其实很好,我只需要更新CloudFormation管道栈来应用它(我以为github webhook会触发这一点,但它只更新管道内的动作)。

amazon-web-services amazon-cloudformation aws-codepipeline aws-codebuild
1个回答
1
投票

我可以确认,你在部署动作中使用的语法是:#{codepipeline PipelineExecutionId}。纠正:

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

I 确凿 我的Pipeline上有CloudFormation提供商。我可以 并确认是否如愿.

如果你编辑了CFN动作,你可以在控制台检查参数是否正确设置。

enter image description here

现在我还不能验证构建动作,但从外观上看,它似乎也没有问题。

© www.soinside.com 2019 - 2024. All rights reserved.