AWS CloudFormation
User Guide (API 版本 2010-05-15)
AWS 文档中描述的 AWS 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 Amazon AWS 入门

AWS::CodeBuild::Project

AWS::CodeBuild::Project 资源配置 AWS CodeBuild 生成源代码的方式。例如,它将告知 AWS CodeBuild 源代码的获取位置以及要使用的生成环境。

语法

要在 AWS CloudFormation 模板中声明此实体,请使用以下语法:

JSON

{ "Type" : "AWS::CodeBuild::Project", "Properties" : { "Artifacts" : Artifacts, "BadgeEnabled" : Boolean, "Cache" : ProjectCache, "Description" : String, "EncryptionKey" : String, "Environment" : Environment, "Name" : String, "ServiceRole" : String, "Source" : Source, "Tags" : [ Resource Tag, ... ], "TimeoutInMinutes" : Integer, "VpcConfig" : VpcConfig } }

YAML

Type: "AWS::CodeBuild::Project" Properties: Artifacts: Artifacts BadgeEnabled: Boolean Cache: ProjectCache Description: String EncryptionKey: String Environment: Environment Name: String ServiceRole: String Source: Source Tags: - Resource Tag TimeoutInMinutes: Integer VpcConfig: VpcConfig

属性

Artifacts

项目在生成期间生成的项目的输出设置。

Required: Yes

Type: AWS CodeBuild 项目构件

更新要求无需中断

BadgeEnabled

指示 AWS CodeBuild 是否为您项目的构建徽章生成可公开访问的 URL。有关更多信息,请参阅 AWS CodeBuild 用户指南 中的构建徽章示例

必需:否

类型:布尔值

更新要求无需中断

Cache

AWS CodeBuild 用于存储和重复使用构建依赖项的设置。

必需:否

类型AWS CodeBuild 项目 ProjectCache

更新要求无需中断

Description

项目的描述。使用此描述可标识项目的目的。

Required: No

Type: String

更新要求无需中断

EncryptionKey

AWS CodeBuild 用于加密生成输出的 AWS Key Management Service (AWS KMS) 客户主密钥 (CMK) 的别名或 Amazon 资源名称 (ARN)。如果您未指定值,AWS CodeBuild 将使用适用于 Amazon Simple Storage Service 的 AWS 托管的 CMK。

Required: No

Type: String

更新要求无需中断

Environment

项目的生成环境设置,如环境类型或要用于生成环境的环境变量。

Required: Yes

Type: AWS CodeBuild 项目环境

更新要求无需中断

Name

项目的名称。此名称在您的 AWS 账户的所有项目中必须是唯一的。

Required: Yes

Type: String

更新要求替换

ServiceRole

AWS CodeBuild 用于代表您与服务进行交互的服务角色的 ARN。

Required: Yes

Type: String

更新要求无需中断

Source

项目的源代码设置,如源代码的存储库类型和位置。

Required: Yes

Type: AWS CodeBuild 项目源

更新要求无需中断

Tags

AWS CodeBuild 项目的任意标签组 (键值对)。

Required: No

Type: AWS CloudFormation 资源标签

更新要求无需中断

TimeoutInMinutes

一个时段 (以分钟为单位),在此时段后,AWS CodeBuild 将停止未完成的生成。有关有效值,请参阅 AWS CodeBuild 用户指南 中的 timeoutInMinutes 字段。

Required: No

Type: Integer

更新要求无需中断

VpcConfig

使 AWS CodeBuild 能够访问 Amazon VPC 中的资源的设置。有关更多信息,请参阅 AWS CodeBuild 用户指南 中的将 AWS CodeBuild 与 Amazon Virtual Private Cloud 结合使用

必需:否

类型AWS CodeBuild 项目 VpcConfig

更新要求无需中断

返回值

Ref

当向 Ref 内部函数提供此资源的逻辑 ID 时,Ref 将返回 AWS CodeBuild 项目的名称,如 myProjectName

有关使用 Ref 功能的更多信息,请参阅参考

Fn::GetAtt

Fn::GetAtt 返回一个此类型指定属性的值。此部分列出了可用属性和示例返回值。

Arn

AWS CodeBuild 项目的 ARN,例如 arn:aws:codebuild:us-west-2:123456789012:project/myProjectName

有关使用 Fn::GetAtt 的更多信息,请参见 Fn::GetAtt

示例

以下示例创建一个 AWS CodeBuild 项目。

JSON

{ "Project": { "Type": "AWS::CodeBuild::Project", "Properties": { "Name": "myProjectName", "Description": "A description about my project", "ServiceRole": { "Fn::GetAtt": [ "ServiceRole", "Arn" ] }, "Artifacts": { "Type": "no_artifacts" }, "Environment": { "Type": "LINUX_CONTAINER", "ComputeType": "BUILD_GENERAL1_SMALL", "Image": "aws/codebuild/java:openjdk-8", "EnvironmentVariables": [ { "Name": "varName", "Value": "varValue" } ] }, "Source": { "Location": "codebuild-demo-test/0123ab9a371ebf0187b0fe5614fbb72c", "Type": "S3" }, "TimeoutInMinutes": 10, "Tags": [ { "Key": "Key1", "Value": "Value1" }, { "Key": "Key2", "Value": "Value2" } ] } } }

YAML

Project: Type: AWS::CodeBuild::Project Properties: Name: myProjectName Description: A description about my project ServiceRole: !GetAtt ServiceRole.Arn Artifacts: Type: no_artifacts Environment: Type: LINUX_CONTAINER ComputeType: BUILD_GENERAL1_SMALL Image: aws/codebuild/java:openjdk-8 EnvironmentVariables: - Name: varName Value: varValue Source: Location: codebuild-demo-test/0123ab9a371ebf0187b0fe5614fbb72c Type: S3 TimeoutInMinutes: 10 Tags: - Key: Key1 Value: Value1 - Key: Key2 Value: Value2

以下示例创建一个在 Amazon S3 中缓存构建依赖项并且使用 Amazon VPC 中的资源的项目。

JSON

{ "Resources": { "CodeBuildProject": { "Type": "AWS::CodeBuild::Project", "Properties": { "ServiceRole": { "Ref": "CodeBuildRole" }, "Artifacts": { "Type": "CODEPIPELINE" }, "BadgeEnabled": "true", "Environment": { "Type": "LINUX_CONTAINER", "ComputeType": "BUILD_GENERAL1_SMALL", "Image": "aws/codebuild/ubuntu-base:14.04", "EnvironmentVariables": [ { "Name": "varName1", "Value": "varValue1" }, { "Name": "varName2", "Value": "varValue2", "Type": "PLAINTEXT" }, { "Name": "varName3", "Value": "/CodeBuild/testParameter", "Type": "PARAMETER_STORE" } ] }, "Source": { "Type": "CODEPIPELINE" }, "TimeoutInMinutes": 10, "VpcConfig": { "VpcId": { "Ref": "CodeBuildVPC" }, "Subnets": [ { "Ref": "CodeBuildSubnet" } ], "SecurityGroupIds": [ { "Ref": "CodeBuildSecurityGroup" } ] }, "Cache": { "Type": "S3", "Location": "mybucket/prefix" } } }, "CodeBuildRole": { "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { "Statement": [ { "Action": [ "sts:AssumeRole" ], "Effect": "Allow", "Principal": { "Service": [ "codebuild.amazonaws.com" ] } } ], "Version": "2012-10-17" }, "Path": "/", "Policies": [ { "PolicyName": "CodeBuildAccess", "PolicyDocument": { "Version": "2012-10-17", "Statement": [ { "Action": [ "logs:*", "ec2:CreateNetworkInterface", "ec2:DescribeNetworkInterfaces", "ec2:DeleteNetworkInterface", "ec2:DescribeSubnets", "ec2:DescribeSecurityGroups", "ec2:DescribeDhcpOptions", "ec2:DescribeVpcs", "ec2:CreateNetworkInterfacePermission" ], "Effect": "Allow", "Resource": "*" } ] } } ] } }, "CodeBuildVPC": { "Type": "AWS::EC2::VPC", "Properties": { "CidrBlock": "10.0.0.0/16", "EnableDnsSupport": "true", "EnableDnsHostnames": "true", "Tags": [ { "Key": "name", "Value": "codebuild" } ] } }, "CodeBuildSubnet": { "Type": "AWS::EC2::Subnet", "Properties": { "VpcId": { "Ref": "CodeBuildVPC" }, "CidrBlock": "10.0.1.0/24" } }, "CodeBuildSecurityGroup": { "Type": "AWS::EC2::SecurityGroup", "Properties": { "GroupName": "Codebuild Internet Group", "GroupDescription": "CodeBuild SecurityGroup", "VpcId": { "Ref": "CodeBuildVPC" } } } } }

YAML

Resources: CodeBuildProject: Type: AWS::CodeBuild::Project Properties: ServiceRole: !Ref CodeBuildRole Artifacts: Type: CODEPIPELINE BadgeEnabled: 'true' Environment: Type: LINUX_CONTAINER ComputeType: BUILD_GENERAL1_SMALL Image: aws/codebuild/ubuntu-base:14.04 EnvironmentVariables: - Name: varName1 Value: varValue1 - Name: varName2 Value: varValue2 Type: PLAINTEXT - Name: varName3 Value: /CodeBuild/testParameter Type: PARAMETER_STORE Source: Type: CODEPIPELINE TimeoutInMinutes: 10 VpcConfig: VpcId: !Ref CodeBuildVPC Subnets: [!Ref CodeBuildSubnet] SecurityGroupIds: [!Ref CodeBuildSecurityGroup] Cache: Type: S3 Location: mybucket/prefix CodeBuildRole: Type: AWS::IAM::Role Properties: AssumeRolePolicyDocument: Statement: - Action: ['sts:AssumeRole'] Effect: Allow Principal: Service: [codebuild.amazonaws.com] Version: '2012-10-17' Path: / Policies: - PolicyName: CodeBuildAccess PolicyDocument: Version: '2012-10-17' Statement: - Action: - 'logs:*' - 'ec2:CreateNetworkInterface' - 'ec2:DescribeNetworkInterfaces' - 'ec2:DeleteNetworkInterface' - 'ec2:DescribeSubnets' - 'ec2:DescribeSecurityGroups' - 'ec2:DescribeDhcpOptions' - 'ec2:DescribeVpcs' - 'ec2:CreateNetworkInterfacePermission' Effect: Allow Resource: '*' CodeBuildVPC: Type: 'AWS::EC2::VPC' Properties: CidrBlock: 10.0.0.0/16 EnableDnsSupport: 'true' EnableDnsHostnames: 'true' Tags: - Key: name Value: codebuild CodeBuildSubnet: Type: 'AWS::EC2::Subnet' Properties: VpcId: Ref: CodeBuildVPC CidrBlock: 10.0.1.0/24 CodeBuildSecurityGroup: Type: 'AWS::EC2::SecurityGroup' Properties: GroupName: Codebuild Internet Group GroupDescription: 'CodeBuild SecurityGroup' VpcId: !Ref CodeBuildVPC

另请参阅