我的问题:Codepipeline 如何读取 SourceCodeArtifact
中的 json 文件中的字段值?
我有 Gthub 存储库,其中包含一个文件 imageManifest.json
,如下所示:
{
"image_id": "docker.pkg.github.com/my-org/my-repo/my-app",
"image_version": "1.0.1"
}
我希望我的 AWS Codepipeline Source 阶段能够从 imageManifest.json
读取 image_version
的值,并将其作为参数传递给后续的 CloudFormation 操作我的管道的阶段。
作为引用,这是我的源阶段。
Stages:
- Name: GitHubSource
Actions:
- Name: SourceAction
ActionTypeId:
Category: Source
Owner: ThirdParty
Version: '1'
Provider: GitHub
OutputArtifacts:
- Name: SourceCodeArtifact
Configuration:
Owner: !Ref GitHubOwner
Repo: !Ref GitHubRepo
OAuthToken: !Ref GitHubAuthToken
这是我的部署阶段:
- Name: DevQA
Actions:
- Name: DeployInfrastructure
InputArtifacts:
- Name: SourceCodeArtifact
ActionTypeId:
Category: Deploy
Owner: AWS
Provider: CloudFormation
Version: '1'
Configuration:
StackName: !Ref AppName
Capabilities: CAPABILITY_NAMED_IAM
RoleArn: !GetAtt [CloudFormationRole, Arn]
ParameterOverrides: !Sub '{"ImageId": "${image_version??}"}'
请注意,上面最后一行中的 image_version
只是我理想的占位符,用于说明我希望如何使用 image_version
json 值。
Codepipeline 如何读取 SourceCodeArtifact
中 json 文件中字段的值?
步骤函数? lambda ?代码构建?
最佳答案
您可以在源阶段和部署阶段之间使用 CodeBuild 步骤。
在 CodeBuild 步骤中,从 SourceArtifact(由源阶段生成的工件)读取 image_version
并写入工件“模板配置”文件 1这是 CloudFormation 操作的配置属性。该文件可以保存 CloudFormation 堆栈的参数值。使用此文件代替您当前使用的 ParameterOverrides
。
关于aws-lambda - 如何从 AWS Codepipeline 中的 json 文件读取值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63172241/