我有一个用于启动CodeBuild的lambda,并且我为一些环境变量(主要是下载路径)设置了覆盖。
现在我正在迁移到CodePipeline,我正试图找出如何做同样的事情。
对于CodeBuild,我会执行environmentVariablesOverride,然后指定我想要的ENV变量。我找不到任何例子表明我可以用CodePipeline做同样的事情。我希望有人能给我一些指导,告诉我如何才能做到这一点。
感谢你的帮助!
在Cloudformation的管道中传递变量的基本用例:
- 我可以有一个参数MyVar1:
AWSTemplateFormatVersion: "2010-09-09"
Description: CodePipeline
Parameters:
MyVar1:
Type: String
Default: "Whatever
- 在管道定义中,我可以在阶段中有一个动作,将该变量传递给代码构建项目:
- Name: Testing
Actions:
- Name: Testing
ActionTypeId:
Category: Build
Owner: AWS
Provider: CodeBuild
Version: "1"
Configuration:
ProjectName: DeployProject
EnvironmentVariables: !Sub |
[
{"name":MY_VAR_1","value":"${MYVAR1}","type":"PLAINTEXT"}
]
InputArtifacts:
- Name: SourceArtifact
Namespace: DeployVars
RunOrder: 1
名称空间'Deployvars'
- 在我的代码构建项目中,我现在可以引用${MY_VAR_1}
DeployProject:
Type: AWS::CodeBuild::Project
Properties:
Name: DeployProject
Description: Deploy Project
Artifacts:
Type: CODEPIPELINE
Environment:
ComputeType: BUILD_GENERAL1_MEDIUM
Image: aws/codebuild/standard:4.0
PrivilegedMode: true
Type: LINUX_CONTAINER
EnvironmentVariables: []
ServiceRole: !GetAtt MyRole.Arn
Source:
BuildSpec: |
version: 0.2
env:
exported-variables:
- MY_VAR_2
phases:
install:
commands:
- env
- ls -al
- MY_VAR_2='this is a test'
build:
commands:
- echo ${MY_VAR_1}
Type: CODEPIPELINE
注意我已经设置并导出了${MY_VAR_2}
- 我可以通过引用它的命名空间在管道定义中传递${MY_VAR_2}。
- Name: Staging
Actions:
- Name: Staging
ActionTypeId:
Category: Build
Owner: AWS
Provider: CodeBuild
Version: "1"
Configuration:
ProjectName: MyOtherProject
EnvironmentVariables: !Sub |
[
{"name":MY_OTHER_VAR","value":"${DeployVars.MY_VAR_2}","type":"PLAINTEXT"}
]
InputArtifacts:
- Name: SourceArtifact
RunOrder: 1