Namespace Amazon.CDK.AWS.CodeBuild
AWS CodeBuild Construct Library
AWS CodeBuild is a fully managed continuous integration service that compiles source code, runs tests, and produces software packages that are ready to deploy. With CodeBuild, you don’t need to provision, manage, and scale your own build servers. CodeBuild scales continuously and processes multiple builds concurrently, so your builds are not left waiting in a queue. You can get started quickly by using prepackaged build environments, or you can create custom build environments that use your own build tools. With CodeBuild, you are charged by the minute for the compute resources you use.
Source
Build projects are usually associated with a source, which is specified via
the source
property which accepts a class that extends the Source
abstract base class.
The default is to have no source associated with the build project;
the buildSpec
option is required in that case.
Here's a CodeBuild project with no source which simply prints Hello, CodeBuild!
:
new Project(this, "MyProject", new ProjectProps {
BuildSpec = BuildSpec.FromObject(new Dictionary<string, object> {
{ "version", "0.2" },
{ "phases", new Dictionary<string, IDictionary<string, string[]>> {
{ "build", new Struct {
Commands = new [] { "echo \"Hello, CodeBuild!\"" }
} }
} }
})
});
CodeCommitSource
Use an AWS CodeCommit repository as the source of this build:
using Amazon.CDK.AWS.CodeCommit;
var repository = new Repository(this, "MyRepo", new RepositoryProps { RepositoryName = "foo" });
new Project(this, "MyFirstCodeCommitProject", new ProjectProps {
Source = Source.CodeCommit(new CodeCommitSourceProps { Repository = repository })
});
S3Source
Create a CodeBuild project with an S3 bucket as the source:
var bucket = new Bucket(this, "MyBucket");
new Project(this, "MyProject", new ProjectProps {
Source = Source.S3(new S3SourceProps {
Bucket = bucket,
Path = "path/to/file.zip"
})
});
The CodeBuild role will be granted to read just the given path from the given bucket
.
GitHubSource
and GitHubEnterpriseSource
These source types can be used to build code from a GitHub repository. Example:
var gitHubSource = Source.GitHub(new GitHubSourceProps {
Owner = "awslabs",
Repo = "aws-cdk",
Webhook = true, // optional, default: true if `webhookFilters` were provided, false otherwise
WebhookTriggersBatchBuild = true, // optional, default is false
WebhookFilters = new [] { FilterGroup.InEventOf(EventAction.PUSH).AndBranchIs("main").AndCommitMessageIs("the commit message"), FilterGroup.InEventOf(EventAction.RELEASED).AndBranchIs("main") }
});
To provide GitHub credentials, please either go to AWS CodeBuild Console to connect
or call ImportSourceCredentials
to persist your personal access token.
Example:
aws codebuild import-source-credentials --server-type GITHUB --auth-type PERSONAL_ACCESS_TOKEN --token <token_value>
BitBucketSource
This source type can be used to build code from a BitBucket repository.
var bbSource = Source.BitBucket(new BitBucketSourceProps {
Owner = "owner",
Repo = "repo"
});
For all Git sources
For all Git sources, you can fetch submodules while cloning git repo.
var gitHubSource = Source.GitHub(new GitHubSourceProps {
Owner = "awslabs",
Repo = "aws-cdk",
FetchSubmodules = true
});
BuildSpec
The build spec can be provided from a number of different sources
File path relative to the root of the source
You can specify a specific filename that exists within the project's source artifact to use as the buildspec.
var project = new Project(this, "MyProject", new ProjectProps {
BuildSpec = BuildSpec.FromSourceFilename("my-buildspec.yml"),
Source = Source.GitHub(new GitHubSourceProps {
Owner = "awslabs",
Repo = "aws-cdk"
})
});
This will use my-buildspec.yml
file within the awslabs/aws-cdk
repository as the build spec.
File within the CDK project codebuild
You can also specify a file within your cdk project directory to use as the buildspec.
var project = new Project(this, "MyProject", new ProjectProps {
BuildSpec = BuildSpec.FromAsset("my-buildspec.yml")
});
This file will be uploaded to S3 and referenced from the codebuild project.
Inline object
var project = new Project(this, "MyProject", new ProjectProps {
BuildSpec = BuildSpec.FromObject(new Dictionary<string, object> {
{ "version", "0.2" }
})
});
This will result in the buildspec being rendered as JSON within the codebuild project, if you prefer it to be rendered as YAML, use fromObjectToYaml
.
var project = new Project(this, "MyProject", new ProjectProps {
BuildSpec = BuildSpec.FromObjectToYaml(new Dictionary<string, object> {
{ "version", "0.2" }
})
});
Artifacts
CodeBuild Projects can produce Artifacts and upload them to S3. For example:
Bucket bucket;
var project = new Project(this, "MyProject", new ProjectProps {
BuildSpec = BuildSpec.FromObject(new Dictionary<string, object> {
{ "version", "0.2" }
}),
Artifacts = Artifacts.S3(new S3ArtifactsProps {
Bucket = bucket,
IncludeBuildId = false,
PackageZip = true,
Path = "another/path",
Identifier = "AddArtifact1"
})
});
Because we've not set the name
property, this example will set the
overrideArtifactName
parameter, and produce an artifact named as defined in
the Buildspec file, uploaded to an S3 bucket (bucket
). The path will be
another/path
and the artifact will be a zipfile.
CodePipeline
To add a CodeBuild Project as an Action to CodePipeline,
use the PipelineProject
class instead of Project
.
It's a simple class that doesn't allow you to specify sources
,
secondarySources
, artifacts
or secondaryArtifacts
,
as these are handled by setting input and output CodePipeline Artifact
instances on the Action,
instead of setting them on the Project.
var project = new PipelineProject(this, "Project", new PipelineProjectProps { });
For more details, see the readme of the @aws-cdk/aws-codepipeline-actions
package.
Caching
You can save time when your project builds by using a cache. A cache can store reusable pieces of your build environment and use them across multiple builds. Your build project can use one of two types of caching: Amazon S3 or local. In general, S3 caching is a good option for small and intermediate build artifacts that are more expensive to build than to download. Local caching is a good option for large intermediate build artifacts because the cache is immediately available on the build host.
S3 Caching
With S3 caching, the cache is stored in an S3 bucket which is available
regardless from what CodeBuild instance gets selected to run your CodeBuild job
on. When using S3 caching, you must also add in a cache
section to your
buildspec which indicates the files to be cached:
Bucket myCachingBucket;
new Project(this, "Project", new ProjectProps {
Source = Source.BitBucket(new BitBucketSourceProps {
Owner = "awslabs",
Repo = "aws-cdk"
}),
Cache = Cache.Bucket(myCachingBucket),
// BuildSpec with a 'cache' section necessary for S3 caching. This can
// also come from 'buildspec.yml' in your source.
BuildSpec = BuildSpec.FromObject(new Dictionary<string, object> {
{ "version", "0.2" },
{ "phases", new Dictionary<string, IDictionary<string, string[]>> {
{ "build", new Struct {
Commands = new [] { "..." }
} }
} },
{ "cache", new Dictionary<string, string[]> {
{ "paths", new [] { "/root/cachedir/**/*" } }
} }
})
});
Note that two different CodeBuild Projects using the same S3 bucket will not share their cache: each Project will get a unique file in the S3 bucket to store the cache in.
Local Caching
With local caching, the cache is stored on the codebuild instance itself. This is simple, cheap and fast, but CodeBuild cannot guarantee a reuse of instance and hence cannot guarantee cache hits. For example, when a build starts and caches files locally, if two subsequent builds start at the same time afterwards only one of those builds would get the cache. Three different cache modes are supported, which can be turned on individually.
new Project(this, "Project", new ProjectProps {
Source = Source.GitHubEnterprise(new GitHubEnterpriseSourceProps {
HttpsCloneUrl = "https://my-github-enterprise.com/owner/repo"
}),
// Enable Docker AND custom caching
Cache = Cache.Local(LocalCacheMode.DOCKER_LAYER, LocalCacheMode.CUSTOM),
// BuildSpec with a 'cache' section necessary for 'CUSTOM' caching. This can
// also come from 'buildspec.yml' in your source.
BuildSpec = BuildSpec.FromObject(new Dictionary<string, object> {
{ "version", "0.2" },
{ "phases", new Dictionary<string, IDictionary<string, string[]>> {
{ "build", new Struct {
Commands = new [] { "..." }
} }
} },
{ "cache", new Dictionary<string, string[]> {
{ "paths", new [] { "/root/cachedir/**/*" } }
} }
})
});
Environment
By default, projects use a small instance with an Ubuntu 18.04 image. You
can use the environment
property to customize the build environment:
Finally, you can also set the build environment fleet
property to create
a reserved capacity project. See Fleet for more information.
Images
The CodeBuild library supports Linux, Windows, and Mac images via the
LinuxBuildImage
(or LinuxArmBuildImage
), WindowsBuildImage
, and MacBuildImage
classes, respectively.
With the introduction of Lambda compute support, the LinuxLambdaBuildImage
(or LinuxArmLambdaBuildImage
) class
is available for specifying Lambda-compatible images.
You can specify one of the predefined Windows/Linux images by using one
of the constants such as WindowsBuildImage.WIN_SERVER_CORE_2019_BASE
,
WindowsBuildImage.WINDOWS_BASE_2_0
, LinuxBuildImage.STANDARD_2_0
,
LinuxBuildImage.AMAZON_LINUX_2_5
, MacBuildImage.BASE_14
, LinuxArmBuildImage.AMAZON_LINUX_2_ARM
,
LinuxLambdaBuildImage.AMAZON_LINUX_2_NODE_18
or LinuxArmLambdaBuildImage.AMAZON_LINUX_2_NODE_18
.
Alternatively, you can specify a custom image using one of the static methods on
LinuxBuildImage
:
or one of the corresponding methods on WindowsBuildImage
:
or one of the corresponding methods on MacBuildImage
:
or one of the corresponding methods on LinuxArmBuildImage
:
Note: You cannot specify custom images on LinuxLambdaBuildImage
or LinuxArmLambdaBuildImage
images.
Note that the WindowsBuildImage
version of the static methods accepts an optional parameter of type WindowsImageType
,
which can be either WindowsImageType.STANDARD
, the default, or WindowsImageType.SERVER_2019
:
Repository ecrRepository;
new Project(this, "Project", new ProjectProps {
Environment = new BuildEnvironment {
BuildImage = WindowsBuildImage.FromEcrRepository(ecrRepository, "v1.0", WindowsImageType.SERVER_2019),
// optional certificate to include in the build image
Certificate = new BuildEnvironmentCertificate {
Bucket = Bucket.FromBucketName(this, "Bucket", "amzn-s3-demo-bucket"),
ObjectKey = "path/to/cert.pem"
}
}
});
The following example shows how to define an image from a Docker asset:
Environment = new BuildEnvironment {
BuildImage = LinuxBuildImage.FromAsset(this, "MyImage", new DockerImageAssetProps {
Directory = Join(__dirname, "demo-image")
})
}
The following example shows how to define an image from an ECR repository:
Environment = new BuildEnvironment {
BuildImage = LinuxBuildImage.FromEcrRepository(ecrRepository, "v1.0")
}
The following example shows how to define an image from a private docker registry:
Environment = new BuildEnvironment {
BuildImage = LinuxBuildImage.FromDockerRegistry("my-registry/my-repo", new DockerImageOptions {
SecretsManagerCredentials = secrets
})
}
GPU images
The class LinuxGpuBuildImage
contains constants for working with
AWS Deep Learning Container images:
new Project(this, "Project", new ProjectProps {
Environment = new BuildEnvironment {
BuildImage = LinuxGpuBuildImage.DLC_TENSORFLOW_2_1_0_INFERENCE
}
});
One complication is that the repositories for the DLC images are in
different accounts in different AWS regions.
In most cases, the CDK will handle providing the correct account for you;
in rare cases (for example, deploying to new regions)
where our information might be out of date,
you can always specify the account
(along with the repository name and tag)
explicitly using the awsDeepLearningContainersImage
method:
new Project(this, "Project", new ProjectProps {
Environment = new BuildEnvironment {
BuildImage = LinuxGpuBuildImage.AwsDeepLearningContainersImage("tensorflow-inference", "2.1.0-gpu-py36-cu101-ubuntu18.04", "123456789012")
}
});
Alternatively, you can reference an image available in an ECR repository using the LinuxGpuBuildImage.fromEcrRepository(repo[, tag])
method.
Lambda images
The LinuxLambdaBuildImage
(or LinuxArmLambdaBuildImage
) class contains constants for working with
Lambda compute:
new Project(this, "Project", new ProjectProps {
Environment = new BuildEnvironment {
BuildImage = LinuxLambdaBuildImage.AMAZON_LINUX_2_NODE_18
}
});
Visit <a href="https://docs.aws.amazon.com/codebuild/latest/userguide/lambda.html">AWS Lambda compute in AWS CodeBuild</a> for more details.
Fleet
By default, a CodeBuild project will request on-demand compute resources to process your build requests. While being able to scale and handle high load, on-demand resources can also be slow to provision.
Reserved capacity fleets are an alternative to on-demand. Dedicated instances, maintained by CodeBuild, will be ready to fulfill your build requests immediately. Skipping the provisioning step in your project will reduce your build time, at the cost of paying for these reserved instances, even when idling, until they are released.
For more information, see Working with reserved capacity in AWS CodeBuild in the CodeBuild documentation.
var fleet = new Fleet(this, "Fleet", new FleetProps {
ComputeType = FleetComputeType.MEDIUM,
EnvironmentType = EnvironmentType.LINUX_CONTAINER,
BaseCapacity = 1
});
new Project(this, "Project", new ProjectProps {
Environment = new BuildEnvironment {
Fleet = fleet,
BuildImage = LinuxBuildImage.STANDARD_7_0
}
});
You can also import an existing fleet to share its resources among several projects across multiple stacks:
new Project(this, "Project", new ProjectProps {
Environment = new BuildEnvironment {
Fleet = Fleet.FromFleetArn(this, "SharedFleet", "arn:aws:codebuild:us-east-1:123456789012:fleet/MyFleet:ed0d0823-e38a-4c10-90a1-1bf25f50fa76"),
BuildImage = LinuxBuildImage.STANDARD_7_0
}
});
Logs
CodeBuild lets you specify an S3 Bucket, CloudWatch Log Group or both to receive logs from your projects.
By default, logs will go to cloudwatch.
CloudWatch Logs Example
new Project(this, "Project", new ProjectProps {
Logging = new LoggingOptions {
CloudWatch = new CloudWatchLoggingOptions {
LogGroup = new LogGroup(this, "MyLogGroup")
}
}
});
S3 Logs Example
new Project(this, "Project", new ProjectProps {
Logging = new LoggingOptions {
S3 = new S3LoggingOptions {
Bucket = new Bucket(this, "LogBucket")
}
}
});
Debugging builds interactively using SSM Session Manager
Integration with SSM Session Manager makes it possible to add breakpoints to your build commands, pause the build there and log into the container to interactively debug the environment.
To do so, you need to:
If these conditions are met, execution of the command codebuild-breakpoint
will suspend your build and allow you to attach a Session Manager session from
the CodeBuild console.
For more information, see View a running build in Session Manager in the CodeBuild documentation.
Example:
new Project(this, "Project", new ProjectProps {
Environment = new BuildEnvironment {
BuildImage = LinuxBuildImage.STANDARD_7_0
},
SsmSessionPermissions = true,
BuildSpec = BuildSpec.FromObject(new Dictionary<string, object> {
{ "version", "0.2" },
{ "phases", new Dictionary<string, IDictionary<string, string[]>> {
{ "build", new Struct {
Commands = new [] { "codebuild-breakpoint", "./my-build.sh" }
} }
} }
})
});
Credentials
CodeBuild allows you to store credentials used when communicating with various sources, like GitHub:
new GitHubSourceCredentials(this, "CodeBuildGitHubCreds", new GitHubSourceCredentialsProps {
AccessToken = SecretValue.SecretsManager("my-token")
});
and BitBucket:
new BitBucketSourceCredentials(this, "CodeBuildBitBucketCreds", new BitBucketSourceCredentialsProps {
Username = SecretValue.SecretsManager("my-bitbucket-creds", new SecretsManagerSecretOptions { JsonField = "username" }),
Password = SecretValue.SecretsManager("my-bitbucket-creds", new SecretsManagerSecretOptions { JsonField = "password" })
});
Note: the credentials are global to a given account in a given region -
they are not defined per CodeBuild project.
CodeBuild only allows storing a single credential of a given type
(GitHub, GitHub Enterprise or BitBucket)
in a given account in a given region -
any attempt to save more than one will result in an error.
You can use the list-source-credentials
AWS CLI operation
to inspect what credentials are stored in your account.
Test reports
You can specify a test report in your buildspec:
var project = new Project(this, "Project", new ProjectProps {
BuildSpec = BuildSpec.FromObject(new Dictionary<string, object> {
// ...
{ "reports", new Dictionary<string, IDictionary<string, string>> {
{ "myReport", new Struct {
Files = "**/*",
Base-directory = "build/test-results"
} }
} }
})
});
This will create a new test report group,
with the name <ProjectName>-myReport
.
The project's role in the CDK will always be granted permissions to create and use report groups with names starting with the project's name; if you'd rather not have those permissions added, you can opt out of it when creating the project:
Source source;
var project = new Project(this, "Project", new ProjectProps {
Source = source,
GrantReportGroupPermissions = false
});
Alternatively, you can specify an ARN of an existing resource group, instead of a simple name, in your buildspec:
Source source;
// create a new ReportGroup
var reportGroup = new ReportGroup(this, "ReportGroup");
var project = new Project(this, "Project", new ProjectProps {
Source = source,
BuildSpec = BuildSpec.FromObject(new Dictionary<string, object> {
// ...
{ "reports", new Dictionary<string, IDictionary<string, string>> {
{ reportGroup.ReportGroupArn, new Struct {
Files = "**/*",
Base-directory = "build/test-results"
} }
} }
})
});
For a code coverage report, you can specify a report group with the code coverage report group type.
Source source;
// create a new ReportGroup
var reportGroup = new ReportGroup(this, "ReportGroup", new ReportGroupProps {
Type = ReportGroupType.CODE_COVERAGE
});
var project = new Project(this, "Project", new ProjectProps {
Source = source,
BuildSpec = BuildSpec.FromObject(new Dictionary<string, object> {
// ...
{ "reports", new Dictionary<string, IDictionary<string, string>> {
{ reportGroup.ReportGroupArn, new Struct {
Files = "**/*",
Base-directory = "build/coverage-report.xml",
File-format = "JACOCOXML"
} }
} }
})
});
If you specify a report group, you need to grant the project's role permissions to write reports to that report group:
Project project;
ReportGroup reportGroup;
reportGroup.GrantWrite(project);
The created policy will adjust to the report group type. If no type is specified when creating the report group the created policy will contain the action for the test report group type.
For more information on the test reports feature, see the AWS CodeBuild documentation.
Report group deletion
When a report group is removed from a stack (or the stack is deleted), the report
group will be removed according to its removal policy (which by default will
simply orphan the report group and leave it in your AWS account). If the removal
policy is set to RemovalPolicy.DESTROY
, the report group will be deleted as long
as it does not contain any reports.
To override this and force all reports to get deleted during report group deletion,
enable the deleteReports
option as well as setting the removal policy to
RemovalPolicy.DESTROY
.
using Amazon.CDK;
var reportGroup = new ReportGroup(this, "ReportGroup", new ReportGroupProps {
RemovalPolicy = RemovalPolicy.DESTROY,
DeleteReports = true
});
Events
CodeBuild projects can be used either as a source for events or be triggered by events via an event rule.
Using Project as an event target
The aws-cdk-lib/aws-events-targets.CodeBuildProject
allows using an AWS CodeBuild
project as a AWS CloudWatch event rule target:
// start build when a commit is pushed
using Amazon.CDK.AWS.CodeCommit;
using Amazon.CDK.AWS.Events.Targets;
Repository codeCommitRepository;
Project project;
codeCommitRepository.OnCommit("OnCommit", new OnCommitOptions {
Target = new CodeBuildProject(project)
});
Using Project as an event source
To define Amazon CloudWatch event rules for build projects, use one of the onXxx
methods:
using Amazon.CDK.AWS.Events.Targets;
Function fn;
Project project;
var rule = project.OnStateChange("BuildStateChange", new OnEventOptions {
Target = new LambdaFunction(fn)
});
CodeStar Notifications
To define CodeStar Notification rules for Projects, use one of the notifyOnXxx()
methods.
They are very similar to onXxx()
methods for CloudWatch events:
using Amazon.CDK.AWS.Chatbot;
Project project;
var target = new SlackChannelConfiguration(this, "MySlackChannel", new SlackChannelConfigurationProps {
SlackChannelConfigurationName = "YOUR_CHANNEL_NAME",
SlackWorkspaceId = "YOUR_SLACK_WORKSPACE_ID",
SlackChannelId = "YOUR_SLACK_CHANNEL_ID"
});
var rule = project.NotifyOnBuildSucceeded("NotifyOnBuildSucceeded", target);
Secondary sources and artifacts
CodeBuild Projects can get their sources from multiple places, and produce multiple outputs. For example:
using Amazon.CDK.AWS.CodeCommit;
Repository repo;
Bucket bucket;
var project = new Project(this, "MyProject", new ProjectProps {
SecondarySources = new [] { Source.CodeCommit(new CodeCommitSourceProps {
Identifier = "source2",
Repository = repo
}) },
SecondaryArtifacts = new [] { Artifacts.S3(new S3ArtifactsProps {
Identifier = "artifact2",
Bucket = bucket,
Path = "some/path",
Name = "file.zip"
}) }
});
Note that the identifier
property is required for both secondary sources and
artifacts.
The contents of the secondary source is available to the build under the
directory specified by the CODEBUILD_SRC_DIR_<identifier>
environment variable
(so, CODEBUILD_SRC_DIR_source2
in the above case).
The secondary artifacts have their own section in the buildspec, under the
regular artifacts
one. Each secondary artifact has its own section, beginning
with their identifier.
So, a buildspec for the above Project could look something like this:
var project = new Project(this, "MyProject", new ProjectProps {
// secondary sources and artifacts as above...
BuildSpec = BuildSpec.FromObject(new Dictionary<string, object> {
{ "version", "0.2" },
{ "phases", new Dictionary<string, IDictionary<string, string[]>> {
{ "build", new Struct {
Commands = new [] { "cd $CODEBUILD_SRC_DIR_source2", "touch output2.txt" }
} }
} },
{ "artifacts", new Dictionary<string, IDictionary<string, IDictionary<string, object>>> {
{ "secondary-artifacts", new Struct {
Artifact2 = new Struct {
Base-directory = "$CODEBUILD_SRC_DIR_source2",
Files = new [] { "output2.txt" }
}
} }
} }
})
});
Definition of VPC configuration in CodeBuild Project
Typically, resources in an VPC are not accessible by AWS CodeBuild. To enable access, you must provide additional VPC-specific configuration information as part of your CodeBuild project configuration. This includes the VPC ID, the VPC subnet IDs, and the VPC security group IDs. VPC-enabled builds are then able to access resources inside your VPC.
For further Information see https://docs.aws.amazon.com/codebuild/latest/userguide/vpc-support.html
Use Cases VPC connectivity from AWS CodeBuild builds makes it possible to:
Your builds can access any resource that's hosted in your VPC.
Enable Amazon VPC Access in your CodeBuild Projects
Pass the VPC when defining your Project, then make sure to
give the CodeBuild's security group the right permissions
to access the resources that it needs by using the
connections
object.
For example:
ApplicationLoadBalancer loadBalancer;
var vpc = new Vpc(this, "MyVPC");
var project = new Project(this, "MyProject", new ProjectProps {
Vpc = vpc,
BuildSpec = BuildSpec.FromObject(new Dictionary<string, object> { })
});
project.Connections.AllowTo(loadBalancer, Port.Tcp(443));
Project File System Location EFS
Add support for CodeBuild to build on AWS EFS file system mounts using
the new ProjectFileSystemLocation.
The fileSystemLocations
property which accepts a list ProjectFileSystemLocation
as represented by the interface IFileSystemLocations
.
The only supported file system type is EFS
.
For example:
new Project(this, "MyProject", new ProjectProps {
BuildSpec = BuildSpec.FromObject(new Dictionary<string, object> {
{ "version", "0.2" }
}),
FileSystemLocations = new [] { FileSystemLocation.Efs(new EfsFileSystemLocationProps {
Identifier = "myidentifier2",
Location = "myclodation.mydnsroot.com:/loc",
MountPoint = "/media",
MountOptions = "opts"
}) }
});
Here's a CodeBuild project with a simple example that creates a project mounted on AWS EFS:
Batch builds
To enable batch builds you should call enableBatchBuilds()
on the project instance.
It returns an object containing the batch service role that was created,
or undefined
if batch builds could not be enabled, for example if the project was imported.
Source source;
var project = new Project(this, "MyProject", new ProjectProps { Source = source });
if (project.EnableBatchBuilds())
{
Console.WriteLine("Batch builds were enabled");
}
Timeouts
There are two types of timeouts that can be set when creating your Project.
The timeout
property can be used to set an upper limit on how long your Project is able to run without being marked as completed.
The default is 60 minutes.
An example of overriding the default follows.
new Project(this, "MyProject", new ProjectProps {
Timeout = Duration.Minutes(90)
});
The queuedTimeout
property can be used to set an upper limit on how your Project remains queued to run.
There is no default value for this property.
As an example, to allow your Project to queue for up to thirty (30) minutes before the build fails,
use the following code.
new Project(this, "MyProject", new ProjectProps {
QueuedTimeout = Duration.Minutes(30)
});
Limiting concurrency
By default if a new build is triggered it will be run even if there is a previous build already in progress. It is possible to limit the maximum concurrent builds to value between 1 and the account specific maximum limit. By default there is no explicit limit.
new Project(this, "MyProject", new ProjectProps {
ConcurrentBuildLimit = 1
});
Visibility
When you can specify the visibility of the project builds. This setting controls whether the builds are publicly readable or remain private.
Visibility options:
Examples:
new Project(this, "MyProject", new ProjectProps {
Visibility = ProjectVisibility.PUBLIC_READ
});
Classes
Artifacts | Artifacts definition for a CodeBuild Project. |
ArtifactsConfig | The type returned from |
ArtifactsProps | Properties common to all Artifacts classes. |
BatchBuildConfig | The type returned from |
BindToCodePipelineOptions | The extra options passed to the |
BitBucketSourceCredentials | The source credentials used when contacting the BitBucket API. |
BitBucketSourceCredentialsProps | Construction properties of |
BitBucketSourceProps | Construction properties for |
BucketCacheOptions | |
BuildEnvironment | |
BuildEnvironmentCertificate | Location of a PEM certificate on S3. |
BuildEnvironmentVariable | |
BuildEnvironmentVariableType | |
BuildImageBindOptions | Optional arguments to |
BuildImageConfig | The return type from |
BuildSpec | BuildSpec for CodeBuild projects. |
Cache | Cache options for CodeBuild Project. |
CfnFleet | The |
CfnFleet.VpcConfigProperty | Information about the VPC configuration that AWS CodeBuild accesses. |
CfnFleetProps | Properties for defining a |
CfnProject | The |
CfnProject.ArtifactsProperty |
|
CfnProject.BatchRestrictionsProperty | Specifies restrictions for the batch build. |
CfnProject.BuildStatusConfigProperty | Contains information that defines how the AWS CodeBuild build project reports the build status to the source provider. |
CfnProject.CloudWatchLogsConfigProperty |
|
CfnProject.EnvironmentProperty |
|
CfnProject.EnvironmentVariableProperty |
|
CfnProject.GitSubmodulesConfigProperty |
|
CfnProject.LogsConfigProperty |
|
CfnProject.ProjectBuildBatchConfigProperty | Contains configuration information about a batch build project. |
CfnProject.ProjectCacheProperty |
|
CfnProject.ProjectFileSystemLocationProperty | Information about a file system created by Amazon Elastic File System (EFS). |
CfnProject.ProjectFleetProperty | Information about the compute fleet of the build project. |
CfnProject.ProjectSourceVersionProperty | A source identifier and its corresponding version. |
CfnProject.ProjectTriggersProperty |
|
CfnProject.RegistryCredentialProperty |
|
CfnProject.S3LogsConfigProperty |
|
CfnProject.ScopeConfigurationProperty | Contains configuration information about the scope for a webhook. |
CfnProject.SourceAuthProperty |
|
CfnProject.SourceProperty |
|
CfnProject.VpcConfigProperty |
|
CfnProject.WebhookFilterProperty |
|
CfnProjectProps | Properties for defining a |
CfnReportGroup | Represents a report group. |
CfnReportGroup.ReportExportConfigProperty | Information about the location where the run of a report is exported. |
CfnReportGroup.S3ReportExportConfigProperty | Information about the S3 bucket where the raw data of a report are exported. |
CfnReportGroupProps | Properties for defining a |
CfnSourceCredential | Information about the credentials for a GitHub, GitHub Enterprise, or Bitbucket repository. |
CfnSourceCredentialProps | Properties for defining a |
CloudWatchLoggingOptions | Information about logs built to a CloudWatch Log Group for a build project. |
CodeCommitSourceProps | Construction properties for |
CommonProjectProps | |
ComputeType | Build machine compute type. |
DockerImageOptions | The options when creating a CodeBuild Docker build image using |
EfsFileSystemLocationProps | Construction properties for |
EnvironmentType | Build environment type. |
EventAction | The types of webhook event actions. |
FileSystemConfig | The type returned from |
FileSystemLocation | FileSystemLocation provider definition for a CodeBuild Project. |
FilterGroup | An object that represents a group of filter conditions for a webhook. |
Fleet | Fleet for a reserved capacity CodeBuild project. |
FleetComputeType | Fleet build machine compute type. Subset of Fleet compatible {@link ComputeType} values. |
FleetProps | Construction properties of a CodeBuild {@link Fleet}. |
GitHubEnterpriseSourceCredentials | The source credentials used when contacting the GitHub Enterprise API. |
GitHubEnterpriseSourceCredentialsProps | Creation properties for |
GitHubEnterpriseSourceProps | Construction properties for |
GitHubSourceCredentials | The source credentials used when contacting the GitHub API. |
GitHubSourceCredentialsProps | Creation properties for |
GitHubSourceProps | Construction properties for |
ImagePullPrincipalType | The type of principal CodeBuild will use to pull your build Docker image. |
LinuxArmBuildImage | A CodeBuild image running aarch64 Linux. |
LinuxArmLambdaBuildImage | A CodeBuild image running aarch64 Lambda. |
LinuxBuildImage | A CodeBuild image running x86-64 Linux. |
LinuxGpuBuildImage | A CodeBuild GPU image running Linux. |
LinuxLambdaBuildImage | A CodeBuild image running x86-64 Lambda. |
LocalCacheMode | Local cache modes to enable for the CodeBuild Project. |
LoggingOptions | Information about logs for the build project. |
MacBuildImage | A CodeBuild image running ARM MacOS. |
PhaseChangeEvent | Event fields for the CodeBuild "phase change" event. |
PipelineProject | A convenience class for CodeBuild Projects that are used in CodePipeline. |
PipelineProjectProps | |
Project | A representation of a CodeBuild Project. |
ProjectNotificationEvents | The list of event types for AWS Codebuild. |
ProjectNotifyOnOptions | Additional options to pass to the notification rule. |
ProjectProps | |
ProjectVisibility | Specifies the visibility of the project's builds. |
ReportGroup | The ReportGroup resource class. |
ReportGroupProps | Construction properties for |
ReportGroupType | The type of reports in the report group. |
S3ArtifactsProps | Construction properties for |
S3LoggingOptions | Information about logs built to an S3 bucket for a build project. |
S3SourceProps | Construction properties for |
Source | Source provider definition for a CodeBuild Project. |
SourceConfig | The type returned from |
SourceProps | Properties common to all Source classes. |
StateChangeEvent | Event fields for the CodeBuild "state change" event. |
UntrustedCodeBoundaryPolicy | Permissions Boundary for a CodeBuild Project running untrusted code. |
UntrustedCodeBoundaryPolicyProps | Construction properties for UntrustedCodeBoundaryPolicy. |
WindowsBuildImage | A CodeBuild image running Windows. |
WindowsImageType | Environment type for Windows Docker images. |
Interfaces
CfnFleet.IVpcConfigProperty | Information about the VPC configuration that AWS CodeBuild accesses. |
CfnProject.IArtifactsProperty |
|
CfnProject.IBatchRestrictionsProperty | Specifies restrictions for the batch build. |
CfnProject.IBuildStatusConfigProperty | Contains information that defines how the AWS CodeBuild build project reports the build status to the source provider. |
CfnProject.ICloudWatchLogsConfigProperty |
|
CfnProject.IEnvironmentProperty |
|
CfnProject.IEnvironmentVariableProperty |
|
CfnProject.IGitSubmodulesConfigProperty |
|
CfnProject.ILogsConfigProperty |
|
CfnProject.IProjectBuildBatchConfigProperty | Contains configuration information about a batch build project. |
CfnProject.IProjectCacheProperty |
|
CfnProject.IProjectFileSystemLocationProperty | Information about a file system created by Amazon Elastic File System (EFS). |
CfnProject.IProjectFleetProperty | Information about the compute fleet of the build project. |
CfnProject.IProjectSourceVersionProperty | A source identifier and its corresponding version. |
CfnProject.IProjectTriggersProperty |
|
CfnProject.IRegistryCredentialProperty |
|
CfnProject.IS3LogsConfigProperty |
|
CfnProject.IScopeConfigurationProperty | Contains configuration information about the scope for a webhook. |
CfnProject.ISourceAuthProperty |
|
CfnProject.ISourceProperty |
|
CfnProject.IVpcConfigProperty |
|
CfnProject.IWebhookFilterProperty |
|
CfnReportGroup.IReportExportConfigProperty | Information about the location where the run of a report is exported. |
CfnReportGroup.IS3ReportExportConfigProperty | Information about the S3 bucket where the raw data of a report are exported. |
IArtifacts | The abstract interface of a CodeBuild build output. |
IArtifactsConfig | The type returned from |
IArtifactsProps | Properties common to all Artifacts classes. |
IBatchBuildConfig | The type returned from |
IBindableBuildImage | A variant of |
IBindToCodePipelineOptions | The extra options passed to the |
IBitBucketSourceCredentialsProps | Construction properties of |
IBitBucketSourceProps | Construction properties for |
IBucketCacheOptions | |
IBuildEnvironment | |
IBuildEnvironmentCertificate | Location of a PEM certificate on S3. |
IBuildEnvironmentVariable | |
IBuildImage | Represents a Docker image used for the CodeBuild Project builds. |
IBuildImageBindOptions | Optional arguments to |
IBuildImageConfig | The return type from |
ICfnFleetProps | Properties for defining a |
ICfnProjectProps | Properties for defining a |
ICfnReportGroupProps | Properties for defining a |
ICfnSourceCredentialProps | Properties for defining a |
ICloudWatchLoggingOptions | Information about logs built to a CloudWatch Log Group for a build project. |
ICodeCommitSourceProps | Construction properties for |
ICommonProjectProps | |
IDockerImageOptions | The options when creating a CodeBuild Docker build image using |
IEfsFileSystemLocationProps | Construction properties for |
IFileSystemConfig | The type returned from |
IFileSystemLocation | The interface of a CodeBuild FileSystemLocation. |
IFleet | Represents a {@link Fleet} for a reserved capacity CodeBuild project. |
IFleetProps | Construction properties of a CodeBuild {@link Fleet}. |
IGitHubEnterpriseSourceCredentialsProps | Creation properties for |
IGitHubEnterpriseSourceProps | Construction properties for |
IGitHubSourceCredentialsProps | Creation properties for |
IGitHubSourceProps | Construction properties for |
ILoggingOptions | Information about logs for the build project. |
IPipelineProjectProps | |
IProject | |
IProjectNotifyOnOptions | Additional options to pass to the notification rule. |
IProjectProps | |
IReportGroup | The interface representing the ReportGroup resource - either an existing one, imported using the |
IReportGroupProps | Construction properties for |
IS3ArtifactsProps | Construction properties for |
IS3LoggingOptions | Information about logs built to an S3 bucket for a build project. |
IS3SourceProps | Construction properties for |
ISource | The abstract interface of a CodeBuild source. |
ISourceConfig | The type returned from |
ISourceProps | Properties common to all Source classes. |
IUntrustedCodeBoundaryPolicyProps | Construction properties for UntrustedCodeBoundaryPolicy. |