[英]AWS CodePipeline: How to pass output from CloudFormation action to a CodeBuild action
I have an AWS CodePipeline defined in a CloudFormation template. 我在CloudFormation模板中定义了AWS CodePipeline。
One of the steps of the pipeline is a CloudFormation action that builds a test environment for my application. 管道的一个步骤是CloudFormation操作,它为我的应用程序构建测试环境。 The URL of the app's Elastic Load Balancer is one of the outputs defined in this template.
应用程序的Elastic Load Balancer的URL是此模板中定义的输出之一。
How do I access this output, so that I can use it in the next step, which is a CodeBuild action that will run api tests against the test environment? 如何访问此输出,以便我可以在下一步中使用它,这是一个CodeBuild操作,将对测试环境运行api测试?
I can specify an OutputFileName
in the CloudFormation Deploy step, but the CodeBuild step would then need 2 input artifacts, the test code and the CloudFormation output file, and there is a maximum of 1 input artifact. 我可以在CloudFormation Deploy步骤中指定
OutputFileName
,但CodeBuild步骤则需要2个输入工件,测试代码和CloudFormation输出文件,并且最多有1个输入工件。
I thought that I could have a step that pushes the CloudFormation output file to S3, so that the api test step can then access it (or simply push it to S3 as part of the CloudFormation::Init code), but I am hoping for something more simple that I could configure in the CodePipeline steps (similar to !ImportValue in CloudFormation). 我认为我可以有一个步骤将CloudFormation输出文件推送到S3,以便api测试步骤可以访问它(或者只是将其作为CloudFormation :: Init代码的一部分推送到S3),但我希望我可以在CodePipeline步骤中配置更简单的东西(类似于CloudFormation中的!ImportValue)。
I also thought that I could assign a 'test url' eg http://test.myapp.com , in the CloudFormation step so that the api tests are always run against that specific url, which would be a great option, except that I am spinning up the test environment dynamically just before the tests (because I don't want the cost of it always running), and I'm not sure that the DNS will have propagated by the time the api tests start running. 我还认为我可以在CloudFormation步骤中分配一个'测试网址',例如http://test.myapp.com ,以便api测试始终针对该特定网址运行,这将是一个很好的选择,除了我我正在测试之前动态调整测试环境(因为我不希望它的成本一直在运行),而且我不确定在api测试开始运行时DNS是否会传播。
Thanks in advance 提前致谢
Definition of CodePipeline CloudFormation action that spins up test environment CodePipeline CloudFormation操作的定义,用于旋转测试环境
...
Name: DeployApplicationInfra
ActionTypeId:
Category: Deploy
Owner: AWS
Version: 1
Provider: CloudFormation
Configuration:
ActionMode: CREATE_UPDATE
Capabilities: CAPABILITY_IAM
OutputFileName: test-application-infra-stack.outputs.json
StackName: test-application-infra-stack
RoleArn: !Ref CloudFormationServiceRoleArn
TemplateConfiguration: AppInfraCfnTemplate::test-application-infra.config.json
TemplatePath: AppInfraCfnTemplate::application-infra.yml
InputArtifacts:
- Name: AppInfraCfnTemplate
OutputArtifacts:
- Name: TestApplicationInfraStackOutputs
Definition of CodePipeline CodeBuild action to run api tests 用于运行api测试的CodePipeline CodeBuild操作的定义
...
Name: RunApiTests
ActionTypeId:
Category: Test
Owner: AWS
Version: 1
Provider: CodeBuild
Configuration:
ProjectName: !Ref ApiTestsBuildProject
InputArtifacts:
- Name: AppSource
...
ApiTestsBuildProject:
Type: AWS::CodeBuild::Project
Properties:
Name: companyinsight-api-tests-build
Artifacts:
Type: CODEPIPELINE
Environment:
ComputeType: BUILD_GENERAL1_SMALL
Image: aws/codebuild/nodejs:8.11.0
Type: LINUX_CONTAINER
ServiceRole: !Ref CIServerBuildRoleArn
Source:
Type: CODEPIPELINE
BuildSpec: !Sub |
version: 0.2
env:
variables:
BASE_URL: <Want to inject test app url here!!!>
phases:
install:
commands:
- npm install
build:
commands:
- npm run api-test
Unfortunately there's no workaround to allow 2 input artifacts for CodeBuild from CodePipeline currently. 不幸的是,目前没有解决方法允许CodePipeline的CodeBuild有2个输入工件。
The alternative I'd recommend for now is to call aws cloudformation describe-stacks from the CLI in your build process and pull the ELB hostname from your stack outputs. 我现在推荐的替代方法是在构建过程中从CLI调用aws cloudformation describe-stacks ,并从堆栈输出中提取ELB主机名。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.