Movatterモバイル変換


[0]ホーム

URL:


Create a build project in AWS CodeBuild - AWS CodeBuild
DocumentationAWS CodeBuildUser Guide
PrerequisitesCreate a build project (console)Create a build project (AWS CLI)Create a build project (AWS SDKs)Create a build project (AWS CloudFormation)

Create a build project in AWS CodeBuild

You can use the AWS CodeBuild console, AWS CLI, or AWS SDKs to create a build project.

Prerequisites

Before creating a build project, answer the questions inPlan a build.

Create a build project (console)

Open the AWS CodeBuild console athttps://console.aws.amazon.com/codesuite/codebuild/home.

If a CodeBuild information page is displayed, chooseCreate build project. Otherwise, on the navigation pane, expandBuild, chooseBuild projects, and then chooseCreate build project.

ChooseCreate build project.

Fill in the following sections. Once complete, chooseCreate build project at the bottom of the page.

Project configuration

Project name

Enter a name for this build project. Build project names must be unique across each AWS account.

Description

Enter an optional description of the build project to help other users understand what this project is used for.

Build badge

(Optional) SelectEnable build badge to make your project's build status visible and embeddable. For more information, seeBuild badges sample.

Enable concurrent build limit

(Optional) If you want to limit the number of concurrent builds for this project, perform the following steps:

New builds are only started if the current number of builds is less than or equal to this limit. If the current build count meets this limit, new builds are throttled and are not run.

Additional information

(Optional) ForTags, enter the name and value of any tags that you want supporting AWS services to use. UseAdd row to add a tag. You can add up to 50 tags.

Source

Amazon S3
CodeCommit
Bitbucket
Credential

ChooseDefault source credential orCustom source credential and follow the instructions to manage the default source credential or customize the source credential.

Connection type

ChooseCodeConnections,OAuth,App password, orPersonal access token to connect to CodeBuild.

Connection

Select a Bitbucket connection or a Secrets Manager secret to connect through your specified connection type.

Repository

ChooseRepository in my Bitbucket account orPublic repository and enter the repository URL.

Source version

Enter a branch, commit ID, tag, or reference and a commit ID. For more information, seeSource version sample with AWS CodeBuild

Git clone depth

ChooseGit clone depth to create a shallow clone with a history truncated to the specified number of commits. If you want a full clone, chooseFull.

Git submodules

SelectUse Git submodules if you want to include Git submodules in your repository.

Build status

SelectReport build statuses to source provider when your builds start and finish if you want the status of your build's start and completion reported to your source provider.

To be able to report the build status to the source provider, the user associated with the source provider must have write access to the repo. If the user does not have write access, the build status cannot be updated. For more information, seeSource provider access.

ForStatus context, enter the value to be used for thename parameter in the Bitbucket commit status. For more information, seebuild in the Bitbucket API documentation.

ForTarget URL, enter the value to be used for theurl parameter in the Bitbucket commit status. For more information, seebuild in the Bitbucket API documentation.

The status of a build triggered by a webhook is always reported to the source provider. To have the status of a build that is started from the console or an API call reported to the source provider, you must select this setting.

If your project's builds are triggered by a webhook, you must push a new commit to the repo for a change to this setting to take effect.

InPrimary source webhook events, selectRebuild every time a code change is pushed to this repository if you want CodeBuild to build the source code every time a code change is pushed to this repository. For more information about webhooks and filter groups, seeBitbucket webhook events.

GitHub
Credential

ChooseDefault source credential orCustom source credential and follow the instructions to manage the default source credential or customize the source credential.

Connection type

ChooseGitHub App,OAuth, orPersonal access token to connect to CodeBuild.

Connection

Select a GitHub connection or a Secrets Manager secret to connect through your specified connection type.

Repository

ChooseRepository in my GitHub account,Public repository, orGitHub scoped webhook and enter the repository URL.

Source version

Enter a branch, commit ID, tag, or reference and a commit ID. For more information, seeSource version sample with AWS CodeBuild

Git clone depth

ChooseGit clone depth to create a shallow clone with a history truncated to the specified number of commits. If you want a full clone, chooseFull.

Git submodules

SelectUse Git submodules if you want to include Git submodules in your repository.

Build status

SelectReport build statuses to source provider when your builds start and finish if you want the status of your build's start and completion reported to your source provider.

To be able to report the build status to the source provider, the user associated with the source provider must have write access to the repo. If the user does not have write access, the build status cannot be updated. For more information, seeSource provider access.

ForStatus context, enter the value to be used for thecontext parameter in the GitHub commit status. For more information, seeCreate a commit status in the GitHub developer guide.

ForTarget URL, enter the value to be used for thetarget_url parameter in the GitHub commit status. For more information, seeCreate a commit status in the GitHub developer guide.

The status of a build triggered by a webhook is always reported to the source provider. To have the status of a build that is started from the console or an API call reported to the source provider, you must select this setting.

If your project's builds are triggered by a webhook, you must push a new commit to the repo for a change to this setting to take effect.

InPrimary source webhook events, selectRebuild every time a code change is pushed to this repository if you want CodeBuild to build the source code every time a code change is pushed to this repository. For more information about webhooks and filter groups, seeGitHub webhook events.

GitHub Enterprise Server
Credential

ChooseDefault source credential orCustom source credential and follow the instructions to manage the default source credential or customize the source credential.

Connection type

ChooseCodeConnections orPersonal access token to connect to CodeBuild.

Connection

Select a GitHub Enterprise connection or a Secrets Manager secret to connect through your specified connection type.

Repository

ChooseRepository in my GitHub Enterprise account orGitHub Enterprise scoped webhook and enter the repository URL.

Source version

Enter a pull request, branch, commit ID, tag, or reference and a commit ID. For more information, seeSource version sample with AWS CodeBuild.

Git clone depth

ChooseGit clone depth to create a shallow clone with a history truncated to the specified number of commits. If you want a full clone, chooseFull.

Git submodules

SelectUse Git submodules if you want to include Git submodules in your repository.

Build status

SelectReport build statuses to source provider when your builds start and finish if you want the status of your build's start and completion reported to your source provider.

To be able to report the build status to the source provider, the user associated with the source provider must have write access to the repo. If the user does not have write access, the build status cannot be updated. For more information, seeSource provider access.

ForStatus context, enter the value to be used for thecontext parameter in the GitHub commit status. For more information, seeCreate a commit status in the GitHub developer guide.

ForTarget URL, enter the value to be used for thetarget_url parameter in the GitHub commit status. For more information, seeCreate a commit status in the GitHub developer guide.

The status of a build triggered by a webhook is always reported to the source provider. To have the status of a build that is started from the console or an API call reported to the source provider, you must select this setting.

If your project's builds are triggered by a webhook, you must push a new commit to the repo for a change to this setting to take effect.

Insecure SSL

SelectEnable insecure SSL to ignore SSL warnings while connecting to your GitHub Enterprise project repository.

InPrimary source webhook events, selectRebuild every time a code change is pushed to this repository if you want CodeBuild to build the source code every time a code change is pushed to this repository. For more information about webhooks and filter groups, seeGitHub webhook events.

GitLab
Credential

ChooseDefault source credential orCustom source credential and follow the instructions to manage the default source credential or customize the source credential.

Connection type

CodeConnections is used to connect GitLab to CodeBuild.

Connection

Select a GitLab connection to connect through CodeConnections.

Repository

Choose the repository you want to use.

Source version

Enter a pull request ID, branch, commit ID, tag, or reference and a commit ID. For more information, seeSource version sample with AWS CodeBuild.

Git clone depth

ChooseGit clone depth to create a shallow clone with a history truncated to the specified number of commits. If you want a full clone, chooseFull.

Build status

SelectReport build statuses to source provider when your builds start and finish if you want the status of your build's start and completion reported to your source provider.

To be able to report the build status to the source provider, the user associated with the source provider must have write access to the repo. If the user does not have write access, the build status cannot be updated. For more information, seeSource provider access.

GitLab Self Managed
Credential

ChooseDefault source credential orCustom source credential and follow the instructions to manage the default source credential or customize the source credential.

Connection type

CodeConnections is used to connect GitLab Self Managed to CodeBuild.

Connection

Select a GitLab Self Managed connection to connect through CodeConnections.

Repository

Choose the repository you want to use.

Source version

Enter a pull request ID, branch, commit ID, tag, or reference and a commit ID. For more information, seeSource version sample with AWS CodeBuild.

Git clone depth

ChooseGit clone depth to create a shallow clone with a history truncated to the specified number of commits. If you want a full clone, chooseFull.

Build status

SelectReport build statuses to source provider when your builds start and finish if you want the status of your build's start and completion reported to your source provider.

To be able to report the build status to the source provider, the user associated with the source provider must have write access to the repo. If the user does not have write access, the build status cannot be updated. For more information, seeSource provider access.

Environment

Provisioning model

Do one of the following:

  • To use on-demand fleets managed by AWS CodeBuild, chooseOn-demand. With on-demand fleets, CodeBuild provides compute for your builds. The machines are destroyed when the build finishes. On-demand fleets are fully managed, and includes automatic scaling capabilities to handle spikes in demand.

  • To use reserved capacity fleets managed by AWS CodeBuild, chooseReserved capacity, and then select aFleet name. With reserved capacity fleets, you configure a set of dedicated instances for your build environment. These machines remain idle, ready to process builds or tests immediately and reduces build durations. With reserved capacity fleets, your machines are always running and will continue to incur costs as long they're provisioned.

For information, seeRun builds on reserved capacity fleets.

Environment image

Do one of the following:

  • To use a Docker image managed by AWS CodeBuild, chooseManaged image, and then make selections fromOperating system,Runtime(s),Image, andImage version. Make a selection fromEnvironment type if it is available.

  • To use another Docker image, chooseCustom image. ForEnvironment type, chooseARM,Linux,Linux GPU, orWindows. If you chooseOther registry, forExternal registry URL, enter the name and tag of the Docker image in Docker Hub, using the formatdocker repository/docker image name. If you chooseAmazon ECR, useAmazon ECR repository andAmazon ECR image to choose the Docker image in your AWS account.

  • To use a private Docker image, chooseCustom image. ForEnvironment type, chooseARM,Linux,Linux GPU, orWindows. ForImage registry, chooseOther registry, and then enter the ARN of the credentials for your private Docker image. The credentials must be created by Secrets Manager. For more information, seeWhat Is AWS Secrets Manager? in theAWS Secrets Manager User Guide.

Compute

Do one of the following:

Service role

Do one of the following:

  • If you do not have a CodeBuild service role, chooseNew service role. InRole name, enter a name for the new role.

  • If you have a CodeBuild service role, chooseExisting service role. InRole ARN, choose the service role.

Additional configuration
Auto-retry limit

Specify the number of additional automatic retries after a failed build. For example, if the auto-retry limit is set to 2, CodeBuild will call theRetryBuild API to automatically retry your build for up to 2 additional times.

Timeout

Specify a value, between 5 minutes and 36 hours, after which CodeBuild stops the build if it is not complete. Ifhours andminutes are left blank, the default value of 60 minutes is used.

Privileged

(Optional) SelectEnable this flag if you want to build Docker images or want your builds to get elevated privileges only if you plan to use this build project to build Docker images. Otherwise, all associated builds that attempt to interact with the Docker daemon fail. You must also start the Docker daemon so that your builds can interact with it. One way to do this is to initialize the Docker daemon in theinstall phase of your build spec by running the following build commands. Do not run these commands if you chose a build environment image provided by CodeBuild with Docker support.

- nohup /usr/local/bin/dockerd --host=unix:///var/run/docker.sock --host=tcp://127.0.0.1:2375 --storage-driver=overlay2 &- timeout 15 sh -c "until docker info; do echo .; sleep 1; done"
VPC

If you want CodeBuild to work with your VPC:

For more information, seeUse AWS CodeBuild with Amazon Virtual Private Cloud.

Compute

Choose one of the available options.

Registry credential

Specify a registry credential when the project is configured with a non-private registry image.

Environment variables

Enter the name and value, and then choose the type of each environment variable for builds to use.

Console and AWS CLI users can see environment variables. If you have no concerns about the visibility of your environment variable, set theName andValue fields, and then setType toPlaintext.

We recommend that you store an environment variable with a sensitive value, such as an AWS access key ID, an AWS secret access key, or a password as a parameter in Amazon EC2 Systems Manager Parameter Store or AWS Secrets Manager.

If you use Amazon EC2 Systems Manager Parameter Store, then forType, chooseParameter. ForName, enter an identifier for CodeBuild to reference. ForValue, enter the parameter's name as stored in Amazon EC2 Systems Manager Parameter Store. Using a parameter named/CodeBuild/dockerLoginPassword as an example, forType, chooseParameter. ForName, enterLOGIN_PASSWORD. ForValue, enter/CodeBuild/dockerLoginPassword.

If you use Amazon EC2 Systems Manager Parameter Store, we recommend that you store parameters with parameter names that start with/CodeBuild/ (for example,/CodeBuild/dockerLoginPassword). You can use the CodeBuild console to create a parameter in Amazon EC2 Systems Manager. ChooseCreate parameter, and then follow the instructions in the dialog box. (In that dialog box, forKMS key, you can specify the ARN of an AWS KMS key in your account. Amazon EC2 Systems Manager uses this key to encrypt the parameter's value during storage and decrypt it during retrieval.) If you use the CodeBuild console to create a parameter, the console starts the parameter name with/CodeBuild/ as it is being stored. For more information, seeSystems Manager Parameter Store andSystems Manager Parameter Store Console Walkthrough in theAmazon EC2 Systems Manager User Guide.

If your build project refers to parameters stored in Amazon EC2 Systems Manager Parameter Store, the build project's service role must allow thessm:GetParameters action. If you choseNew service role earlier, CodeBuild includes this action in the default service role for your build project. However, if you choseExisting service role, you must include this action to your service role separately.

If your build project refers to parameters stored in Amazon EC2 Systems Manager Parameter Store with parameter names that do not start with/CodeBuild/, and you choseNew service role, you must update that service role to allow access to parameter names that do not start with/CodeBuild/. This is because that service role allows access only to parameter names that start with/CodeBuild/.

If you chooseNew service role, the service role includes permission to decrypt all parameters under the/CodeBuild/ namespace in the Amazon EC2 Systems Manager Parameter Store.

Environment variables you set replace existing environment variables. For example, if the Docker image already contains an environment variable namedMY_VAR with a value ofmy_value, and you set an environment variable namedMY_VAR with a value ofother_value, thenmy_value is replaced byother_value. Similarly, if the Docker image already contains an environment variable namedPATH with a value of/usr/local/sbin:/usr/local/bin, and you set an environment variable namedPATH with a value of$PATH:/usr/share/ant/bin, then/usr/local/sbin:/usr/local/bin is replaced by the literal value$PATH:/usr/share/ant/bin.

Do not set any environment variable with a name that begins withCODEBUILD_. This prefix is reserved for internal use.

If an environment variable with the same name is defined in multiple places, the value is determined as follows:

  • The value in the start build operation call takes highest precedence.

  • The value in the build project definition takes next precedence.

  • The value in the buildspec declaration takes lowest precedence.

If you use Secrets Manager, forType, chooseSecrets Manager. ForName, enter an identifier for CodeBuild to reference. ForValue, enter areference-key using the patternsecret-id:json-key:version-stage:version-id. For information, seeSecrets Manager reference-key in the buildspec file.

If you use Secrets Manager, we recommend that you store secrets with names that start with/CodeBuild/ (for example,/CodeBuild/dockerLoginPassword). For more information, seeWhat Is AWS Secrets Manager? in theAWS Secrets Manager User Guide.

If your build project refers to secrets stored in Secrets Manager, the build project's service role must allow thesecretsmanager:GetSecretValue action. If you choseNew service role earlier, CodeBuild includes this action in the default service role for your build project. However, if you choseExisting service role, you must include this action to your service role separately.

If your build project refers to secrets stored in Secrets Manager with secret names that do not start with/CodeBuild/, and you choseNew service role, you must update the service role to allow access to secret names that do not start with/CodeBuild/. This is because the service role allows access only to secret names that start with/CodeBuild/.

If you chooseNew service role, the service role includes permission to decrypt all secrets under the/CodeBuild/ namespace in the Secrets Manager.

Buildspec

Build specifications

Do one of the following:

  • If your source code includes a buildspec file, chooseUse a buildspec file. By default, CodeBuild looks for a file namedbuildspec.yml in the source code root directory. If your buildspec file uses a different name or location, enter its path from the source root inBuildspec name (for example,buildspec-two.yml orconfiguration/buildspec.yml. If the buildspec file is in an S3 bucket, it must be in the same AWS Region as your build project. Specify the buildspec file using its ARN (for example,arn:aws:s3:::<my-codebuild-sample2>/buildspec.yml).

  • If your source code does not include a buildspec file, or if you want to run build commands different from the ones specified for thebuild phase in thebuildspec.yml file in the source code's root directory, chooseInsert build commands. ForBuild commands, enter the commands you want to run in thebuild phase. For multiple commands, separate each command by&& (for example,mvn test && mvn package). To run commands in other phases, or if you have a long list of commands for thebuild phase, add abuildspec.yml file to the source code root directory, add the commands to the file, and then chooseUse the buildspec.yml in the source code root directory.

For more information, see theBuildspec reference.

Batch configuration

You can run a group of builds as a single operation. For more information, seeRun builds in batches.

Define batch configuration

Select to allow batch builds in this project.

Batch service role

Provides the service role for batch builds.

Choose one of the following:

  • If you do not have a batch service role, chooseNew service role. InService role, enter a name for the new role.

  • If you have a batch service role, chooseExisting service role. InService role, choose the service role.

Batch builds introduce a new security role in the batch configuration. This new role is required as CodeBuild must be able to call theStartBuild,StopBuild, andRetryBuild actions on your behalf to run builds as part of a batch. Customers should use a new role, and not the same role they use in their build, for two reasons:

  • Giving the build roleStartBuild,StopBuild, andRetryBuild permissions would allow a single build to start more builds via the buildspec.

  • CodeBuild batch builds provide restrictions that restrict the number of builds and compute types that can be used for the builds in the batch. If the build role has these permissions, it is possible the builds themselves could bypass these restrictions.

Allowed compute types for batch

Select the compute types allowed for the batch. Select all that apply.

Allowed fleets for batch

Select the fleets allowed for the batch. Select all that apply.

Maximum builds allowed in batch

Enter the maximum number of builds allowed in the batch. If a batch exceeds this limit, the batch will fail.

Batch timeout

Enter the maximum amount of time for the batch build to complete.

Combine artifacts

SelectCombine all artifacts from batch into a single location to have all of the artifacts from the batch combined into a single location.

Batch report mode

Select the desired build status report mode for batch builds.

Artifacts

Type

Do one of the following:

For each secondary set of artifacts you want:

  1. ForArtifact identifier, enter a value that is fewer than 128 characters and contains only alphanumeric characters and underscores.

  2. ChooseAdd artifact.

  3. Follow the previous steps to configure your secondary artifacts.

  4. ChooseSave artifact.

Additional configuration
Encryption key

(Optional) Do one of the following:

  • To use the AWS managed key for Amazon S3 in your account to encrypt the build output artifacts, leaveEncryption key blank. This is the default.

  • To use a customer managed key to encrypt the build output artifacts, inEncryption key, enter the ARN of the KMS key. Use the formatarn:aws:kms:region-ID:account-ID:key/key-ID.

Cache type

ForCache type, choose one of the following:

Using a cache saves considerable build time because reusable pieces of the build environment are stored in the cache and used across builds. For information about specifying a cache in the buildspec file, seeBuildspec syntax. For more information about caching, seeCache builds to improve performance.

Logs

Choose the logs you want to create. You can create Amazon CloudWatch Logs, Amazon S3 logs, or both.

CloudWatch

If you want Amazon CloudWatch Logs logs:

CloudWatch logs

SelectCloudWatch logs.

Group name

Enter the name of your Amazon CloudWatch Logs log group.

Stream name

Enter your Amazon CloudWatch Logs log stream name.

S3

If you want Amazon S3 logs:

S3 logs

SelectS3 logs.

Bucket

Choose the name of the S3 bucket for your logs.

Path prefix

Enter the prefix for your logs.

Disable S3 log encryption

Select if you do not want your S3 logs encrypted.

Create a build project (AWS CLI)

For more information about using the AWS CLI with CodeBuild, see theCommand line reference.

To create a CodeBuild build project using the AWS CLI, you create a JSON-formattedProject structure, fill in the structure, and call thecreate-project command to create the project.

Create the JSON file

Create a skeleton JSON file with thecreate-project command, using the--generate-cli-skeleton option:

aws codebuild create-project --generate-cli-skeleton ><json-file>

This creates a JSON file with the path and file name specified by<json-file>.

Fill in the JSON file

Modify the JSON data as follows and save your results.

{ "name": "<project-name>", "description": "<description>", "source":{ "type": "CODECOMMIT" | "CODEPIPELINE" | "GITHUB" | "GITHUB_ENTERPRISE" | "GITLAB" | "GITLAB_SELF_MANAGED" | "BITBUCKET" | "S3" | "NO_SOURCE", "location": "<source-location>", "gitCloneDepth": "<git-clone-depth>", "buildspec": "<buildspec>", "InsecureSsl": "<insecure-ssl>", "reportBuildStatus": "<report-build-status>", "buildStatusConfig":{ "context": "<context>", "targetUrl": "<target-url>" }, "gitSubmodulesConfig":{ "fetchSubmodules": "<fetch-submodules>" }, "auth":{ "type": "<auth-type>", "resource": "<auth-resource>" }, "sourceIdentifier": "<source-identifier>" }, "secondarySources": [{ "type": "CODECOMMIT" | "CODEPIPELINE" | "GITHUB" | "GITHUB_ENTERPRISE" | "GITLAB" | "GITLAB_SELF_MANAGED" | "BITBUCKET" | "S3" | "NO_SOURCE", "location": "<source-location>", "gitCloneDepth": "<git-clone-depth>", "buildspec": "<buildspec>", "InsecureSsl": "<insecure-ssl>", "reportBuildStatus": "<report-build-status>", "auth":{ "type": "<auth-type>", "resource": "<auth-resource>" }, "sourceIdentifier": "<source-identifier>" } ], "secondarySourceVersions": [{ "sourceIdentifier": "<secondary-source-identifier>", "sourceVersion": "<secondary-source-version>" } ], "sourceVersion": "<source-version>", "artifacts":{ "type": "CODEPIPELINE" | "S3" | "NO_ARTIFACTS", "location": "<artifacts-location>", "path": "<artifacts-path>", "namespaceType": "<artifacts-namespacetype>", "name": "<artifacts-name>", "overrideArtifactName": "<override-artifact-name>", "packaging": "<artifacts-packaging>" }, "secondaryArtifacts": [{ "type": "CODEPIPELINE" | "S3" | "NO_ARTIFACTS", "location": "<secondary-artifact-location>", "path": "<secondary-artifact-path>", "namespaceType": "<secondary-artifact-namespaceType>", "name": "<secondary-artifact-name>", "packaging": "<secondary-artifact-packaging>", "artifactIdentifier": "<secondary-artifact-identifier>" } ], "cache":{ "type": "<cache-type>", "location": "<cache-location>", "mode": [ "<cache-mode>" ] }, "environment":{ "type": "LINUX_CONTAINER" | "LINUX_GPU_CONTAINER" | "ARM_CONTAINER" | "WINDOWS_SERVER_2019_CONTAINER" | "WINDOWS_SERVER_2022_CONTAINER", "image": "<image>", "computeType": "BUILD_GENERAL1_SMALL" | "BUILD_GENERAL1_MEDIUM" | "BUILD_GENERAL1_LARGE" | "BUILD_GENERAL1_2XLARGE", "certificate": "<certificate>", "environmentVariables": [{ "name": "<environmentVariable-name>", "value": "<environmentVariable-value>", "type": "<environmentVariable-type>" } ], "registryCredential": [{ "credential": "<credential-arn-or-name>", "credentialProvider": "<credential-provider>" } ], "imagePullCredentialsType": "CODEBUILD" | "SERVICE_ROLE", "privilegedMode": "<privileged-mode>" }, "serviceRole": "<service-role>", "autoRetryLimit":<auto-retry-limit>, "timeoutInMinutes":<timeout>, "queuedTimeoutInMinutes":<queued-timeout>, "encryptionKey": "<encryption-key>", "tags": [{ "key": "<tag-key>", "value": "<tag-value>" } ], "vpcConfig":{ "securityGroupIds": [ "<security-group-id>" ], "subnets": [ "<subnet-id>" ], "vpcId": "<vpc-id>" }, "badgeEnabled": "<badge-enabled>", "logsConfig":{ "cloudWatchLogs":{ "status": "<cloudwatch-logs-status>", "groupName": "<group-name>", "streamName": "<stream-name>" }, "s3Logs":{ "status": "<s3-logs-status>", "location": "<s3-logs-location>", "encryptionDisabled": "<s3-logs-encryption-disabled>" } }, "fileSystemLocations": [{ "type": "EFS", "location": "<EFS-DNS-name-1>:/<directory-path>", "mountPoint": "<mount-point>", "identifier": "<efs-identifier>", "mountOptions": "<efs-mount-options>" } ], "buildBatchConfig":{ "serviceRole": "<batch-service-role>", "combineArtifacts":<combine-artifacts>, "restrictions":{ "maximumBuildsAllowed":<max-builds>, "computeTypesAllowed": [ "<compute-type>" ], "fleetsAllowed": [ "<fleet-name>" ] }, "timeoutInMins":<batch-timeout>, "batchReportMode": "REPORT_AGGREGATED_BATCH" | "REPORT_INDIVIDUAL_BUILDS" }, "concurrentBuildLimit":<concurrent-build-limit>}

Replace the following:

name

Required. The name for this build project. This name must be unique across all of the build projects in your AWS account.

description

Optional. The description for this build project.

source

Required. AProjectSource object that contains information about this build project's source code settings. After you add asource object, you can add up to 12 more sources using thesecondarySources. These settings include the following:

source/type

Required. The type of repository that contains the source code to build. Valid values include:

  • CODECOMMIT

  • CODEPIPELINE

  • GITHUB

  • GITHUB_ENTERPRISE

  • GITLAB

  • GITLAB_SELF_MANAGED

  • BITBUCKET

  • S3

  • NO_SOURCE

If you useNO_SOURCE, the buildspec cannot be a file because the project does not have a source. Instead, you must use thebuildspec attribute to specify a YAML-formatted string for your buildspec. For more information, seeCreate a build project without a source.

source/location

Required unless you set<source-type> toCODEPIPELINE. The location of the source code for the specified repository type.

  • For CodeCommit, the HTTPS clone URL to the repository that contains the source code and the buildspec file (for example,https://git-codecommit.<region-id>.amazonaws.com/v1/repos/<repo-name>).

  • For Amazon S3, the build input bucket name, followed by the path and name of the ZIP file that contains the source code and the buildspec. For example:

    • For a ZIP file located at the root of the input bucket:<bucket-name>/<object-name>.zip.

    • For a ZIP file located in a subfolder in the input bucket:<bucket-name>/<subfoler-path>/<object-name>.zip.

  • For GitHub, the HTTPS clone URL to the repository that contains the source code and the buildspec file. The URL must contain github.com. You must connect your AWS account to your GitHub account. To do this, use the CodeBuild console to create a build project.

    • ChooseAuthorize application. (After you have connected to your GitHub account, you do not need to finish creating the build project. You can close the CodeBuild console.)

  • For GitHub Enterprise Server, the HTTP or HTTPS clone URL to the repository that contains the source code and the buildspec file. You must also connect your AWS account to your GitHub Enterprise Server account. To do this, use the CodeBuild console to create a build project.

    1. Create a personal access token in GitHub Enterprise Server.

    2. Copy this token to your clipboard so you can use it when you create your CodeBuild project. For more information, seeCreating a personal access token for the command line on the GitHub Help website.

    3. When you use the console to create your CodeBuild project, inSource, forSource provider, chooseGitHub Enterprise.

    4. ForPersonal Access Token, paste the token that was copied to your clipboard. ChooseSave Token. Your CodeBuild account is now connected to your GitHub Enterprise Server account.

  • For GitLab and GitLab self-managed, the HTTPS clone URL to the repository that contains the source code and the buildspec file. Note that if you use GitLab, the URL must contain gitlab.com. If you use GitLab self-managed, the URL does not need to contain gitlab.com. You must connect your AWS account to your GitLab or GitLab self-managed account. To do this, use the CodeBuild console to create a build project.

    • In the Developer Tools navigation pane, chooseSettings,Connections, and thenCreate connection. On this page, create either a GitLab or GitLab self-managed connection, and then chooseConnect to GitLab.

  • For Bitbucket, the HTTPS clone URL to the repository that contains the source code and the buildspec file. The URL must contain bitbucket.org. You must also connect your AWS account to your Bitbucket account. To do this, use the CodeBuild console to create a build project.

    1. When you use the console to connect (or reconnect) with Bitbucket, on the BitbucketConfirm access to your account page, chooseGrant access. (After you have connected to your Bitbucket account, you do not need to finish creating the build project. You can close the CodeBuild console.)

  • For AWS CodePipeline, do not specify alocation value forsource. CodePipeline ignores this value because when you create a pipeline in CodePipeline, you specify the source code location in the Source stage of the pipeline.

source/gitCloneDepth

Optional. The depth of history to download. Minimum value is 0. If this value is 0, greater than 25, or not provided, then the full history is downloaded with each build project. If your source type is Amazon S3, this value is not supported.

source/buildspec

Optional. The build specification definition or file to use. If this value is not provided or is set to an empty string, the source code must contain abuildspec.yml file in its root directory. If this value is set, it can be either an inline buildspec definition, the path to an alternate buildspec file relative to the root directory of your primary source, or the path to an S3 bucket. The bucket must be in the same AWS Region as the build project. Specify the buildspec file using its ARN (for example,arn:aws:s3:::<my-codebuild-sample2>/buildspec.yml). For more information, seeBuildspec file name and storage location.

source/auth

Contains information about the authorization settings for CodeBuild to access the source code to be built.

source/auth/type

Required. The authorization type to use. Valid values are:

  • OAUTH

  • CODECONNECTIONS

  • SECRETS_MANAGER

source/auth/resource

Optional. The resource value that applies to the specified authorization type. This can be the Secrets Manager ARN or the CodeConnections ARN.

source/reportBuildStatus

Specifies whether to send your source provider the status of a build's start and completion. If you set this with a source provider other than GitHub, GitHub Enterprise Server, or Bitbucket, aninvalidInputException is thrown.

To be able to report the build status to the source provider, the user associated with the source provider must have write access to the repo. If the user does not have write access, the build status cannot be updated. For more information, seeSource provider access.

source/buildStatusConfig

Contains information that defines how the CodeBuild build project reports the build status to the source provider. This option is only used when the source type isGITHUB,GITHUB_ENTERPRISE, orBITBUCKET.

source/buildStatusConfig/context

For Bitbucket sources, this parameter is used for thename parameter in the Bitbucket commit status. For GitHub sources, this parameter is used for thecontext parameter in the GitHub commit status.

For example, you can have thecontext contain the build number and the webhook trigger using the CodeBuild environment variables:

AWS CodeBuild sample-project Build #$CODEBUILD_BUILD_NUMBER - $CODEBUILD_WEBHOOK_TRIGGER

This results in the context appearing like this for build #24 triggered by a webhook pull request event:

AWS CodeBuild sample-project Build #24 - pr/8
source/gitSubmodulesConfig

Optional. Information about the Git submodules configuration. Used with CodeCommit, GitHub, GitHub Enterprise Server, and Bitbucket only.

source/InsecureSsl

Optional. Used with GitHub Enterprise Server only. Set this value totrue to ignore TLS warnings while connecting to your GitHub Enterprise Server project repository. The default value isfalse.InsecureSsl should be used for testing purposes only. It should not be used in a production environment.

source/sourceIdentifier

A user-defined identifier for the project source. Optional for the primary source. Required for secondary sources.

secondarySources

Optional. An array ofProjectSource objects that contain information about the secondary sources for a build project. You can add up to 12 secondary sources. ThesecondarySources objects use the same properties used by thesource object. In a secondary source object, thesourceIdentifier is required.

secondarySourceVersions

Optional. An array ofProjectSourceVersion objects. IfsecondarySourceVersions is specified at the build level, then they take precedence over this.

sourceVersion

Optional. The version of the build input to be built for this project. If not specified, the latest version is used. If specified, it must be one of:

  • For CodeCommit, the commit ID, branch, or Git tag to use.

  • For GitHub, the commit ID, pull request ID, branch name, or tag name that corresponds to the version of the source code you want to build. If a pull request ID is specified, it must use the formatpr/pull-request-ID (for examplepr/25). If a branch name is specified, the branch's HEAD commit ID is used. If not specified, the default branch's HEAD commit ID is used.

  • For GitLab, the commit ID, pull request ID, branch name, tag name, or reference and a commit ID. For more information, seeSource version sample with AWS CodeBuild.

  • For Bitbucket, the commit ID, branch name, or tag name that corresponds to the version of the source code you want to build. If a branch name is specified, the branch's HEAD commit ID is used. If not specified, the default branch's HEAD commit ID is used.

  • For Amazon S3, the version ID of the object that represents the build input ZIP file to use.

IfsourceVersion is specified at the build level, then that version takes precedence over thissourceVersion (at the project level). For more information, seeSource version sample with AWS CodeBuild.

artifacts

Required. AProjectArtifacts object that contains information about this build project's output artifact settings. After you add anartifacts object, you can add up to 12 more artifacts using thesecondaryArtifacts. These settings include the following:

artifacts/type

Required. The type of build output artifact. Valid values are:

  • CODEPIPELINE

  • NO_ARTIFACTS

  • S3

artifacts/location

Only used with theS3 artifact type. Not used for other artifact types.

The name of the output bucket you created or identified in the prerequisites.

artifacts/path

Only used with theS3 artifact type. Not used for other artifact types.

The path in of the output bucket to place ZIP file or folder. If you do not specify a value forpath, CodeBuild usesnamespaceType (if specified) andname to determine the path and name of the build output ZIP file or folder. For example, if you specifyMyPath forpath andMyArtifact.zip forname, the path and name would beMyPath/MyArtifact.zip.

artifacts/namespaceType

Only used with theS3 artifact type. Not used for other artifact types.

The namespace of the build output ZIP file or folder. Valid values includeBUILD_ID andNONE. UseBUILD_ID to insert the build ID into the path of the build output ZIP file or folder. Otherwise, useNONE. If you do not specify a value fornamespaceType, CodeBuild usespath (if specified) andname to determine the path and name of the build output ZIP file or folder. For example, if you specifyMyPath forpath,BUILD_ID fornamespaceType, andMyArtifact.zip forname, the path and name would beMyPath/build-ID/MyArtifact.zip.

artifacts/name

Only used with theS3 artifact type. Not used for other artifact types.

The name of the build output ZIP file or folder inside oflocation. For example, if you specifyMyPath forpath andMyArtifact.zip forname, the path and name would beMyPath/MyArtifact.zip.

artifacts/overrideArtifactName

Only used with the S3 artifact type. Not used for other artifact types.

Optional. If set totrue, the name specified in theartifacts block of the buildspec file overridesname. For more information, seeBuild specification reference for CodeBuild.

artifacts/packaging

Only used with theS3 artifact type. Not used for other artifact types.

Optional. Specifies how to package the artifacts. Allowed values are:

NONE

Create a folder that contains the build artifacts. This is the default value.

ZIP

Create a ZIP file that contains the build artifacts.

secondaryArtifacts

Optional. An array ofProjectArtifacts objects that contain information about the secondary artifacts settings for a build project. You can add up to 12 secondary artifacts. ThesecondaryArtifacts uses many of the same settings used by theartifacts object.

cache

Required. AProjectCache object that contains information about this build project's cache settings. For more information, seeCache builds.

environment

Required. AProjectEnvironment object that contains information about this project's build environment settings. These settings include:

environment/type

Required. The type of build environment. For more information, seetype in theCodeBuild API Reference.

environment/image

Required. The Docker image identifier used by this build environment. Typically, this identifier is expressed asimage-name:tag. For example, in the Docker repository that CodeBuild uses to manage its Docker images, this could beaws/codebuild/standard:5.0. In Docker Hub,maven:3.3.9-jdk-8. In Amazon ECR,account-id.dkr.ecr.region-id.amazonaws.com/your-Amazon-ECR-repo-name:tag. For more information, seeDocker images provided by CodeBuild.

environment/computeType

Required. Specifies the compute resources used by this build environment. For more information, seecomputeType in theCodeBuild API Reference.

environment/certificate

Optional. The ARN of the Amazon S3 bucket, path prefix, and object key that contains the PEM-encoded certificate. The object key can be either just the .pem file or a .zip file containing the PEM-encoded certificate. For example, if your Amazon S3 bucket name is<my-bucket>, your path prefix is<cert>, and your object key name is<certificate.pem>, then acceptable formats forcertificate are<my-bucket/cert/certificate.pem> orarn:aws:s3:::<my-bucket/cert/certificate.pem>.

environment/environmentVariables

Optional. An array ofEnvironmentVariable objects that contains the environment variables you want to specify for this build environment. Each environment variable is expressed as an object that contains aname,value, andtype ofname,value, andtype.

Console and AWS CLI users can see all environment variables. If you have no concerns about the visibility of your environment variable, setname andvalue, and settype toPLAINTEXT.

We recommend you store environment variables with sensitive values, such as an AWS access key ID, an AWS secret access key, or a password, as a parameter in Amazon EC2 Systems Manager Parameter Store or AWS Secrets Manager. Forname, for that stored parameter, set an identifier for CodeBuild to reference.

If you use Amazon EC2 Systems Manager Parameter Store, forvalue, set the parameter's name as stored in the Parameter Store. Settype toPARAMETER_STORE. Using a parameter named/CodeBuild/dockerLoginPassword as an example, setname toLOGIN_PASSWORD. Setvalue to/CodeBuild/dockerLoginPassword. Settype toPARAMETER_STORE.

If you use Amazon EC2 Systems Manager Parameter Store, we recommend that you store parameters with parameter names that start with/CodeBuild/ (for example,/CodeBuild/dockerLoginPassword). You can use the CodeBuild console to create a parameter in Amazon EC2 Systems Manager. ChooseCreate parameter, and then follow the instructions in the dialog box. (In that dialog box, forKMS key, you can specify the ARN of an AWS KMS key in your account. Amazon EC2 Systems Manager uses this key to encrypt the parameter's value during storage and decrypt it during retrieval.) If you use the CodeBuild console to create a parameter, the console starts the parameter name with/CodeBuild/ as it is being stored. For more information, seeSystems Manager Parameter Store andSystems Manager Parameter Store Console Walkthrough in theAmazon EC2 Systems Manager User Guide.

If your build project refers to parameters stored in Amazon EC2 Systems Manager Parameter Store, the build project's service role must allow thessm:GetParameters action. If you choseNew service role earlier, CodeBuild includes this action in the default service role for your build project. However, if you choseExisting service role, you must include this action to your service role separately.

If your build project refers to parameters stored in Amazon EC2 Systems Manager Parameter Store with parameter names that do not start with/CodeBuild/, and you choseNew service role, you must update that service role to allow access to parameter names that do not start with/CodeBuild/. This is because that service role allows access only to parameter names that start with/CodeBuild/.

If you chooseNew service role, the service role includes permission to decrypt all parameters under the/CodeBuild/ namespace in the Amazon EC2 Systems Manager Parameter Store.

Environment variables you set replace existing environment variables. For example, if the Docker image already contains an environment variable namedMY_VAR with a value ofmy_value, and you set an environment variable namedMY_VAR with a value ofother_value, thenmy_value is replaced byother_value. Similarly, if the Docker image already contains an environment variable namedPATH with a value of/usr/local/sbin:/usr/local/bin, and you set an environment variable namedPATH with a value of$PATH:/usr/share/ant/bin, then/usr/local/sbin:/usr/local/bin is replaced by the literal value$PATH:/usr/share/ant/bin.

Do not set any environment variable with a name that begins withCODEBUILD_. This prefix is reserved for internal use.

If an environment variable with the same name is defined in multiple places, the value is determined as follows:

  • The value in the start build operation call takes highest precedence.

  • The value in the build project definition takes next precedence.

  • The value in the buildspec declaration takes lowest precedence.

If you use Secrets Manager, forvalue, set the parameter's name as stored in Secrets Manager. Settype toSECRETS_MANAGER. Using a secret named/CodeBuild/dockerLoginPassword as an example, setname toLOGIN_PASSWORD. Setvalue to/CodeBuild/dockerLoginPassword. Settype toSECRETS_MANAGER.

If you use Secrets Manager, we recommend that you store secrets with names that start with/CodeBuild/ (for example,/CodeBuild/dockerLoginPassword). For more information, seeWhat Is AWS Secrets Manager? in theAWS Secrets Manager User Guide.

If your build project refers to secrets stored in Secrets Manager, the build project's service role must allow thesecretsmanager:GetSecretValue action. If you choseNew service role earlier, CodeBuild includes this action in the default service role for your build project. However, if you choseExisting service role, you must include this action to your service role separately.

If your build project refers to secrets stored in Secrets Manager with secret names that do not start with/CodeBuild/, and you choseNew service role, you must update the service role to allow access to secret names that do not start with/CodeBuild/. This is because the service role allows access only to secret names that start with/CodeBuild/.

If you chooseNew service role, the service role includes permission to decrypt all secrets under the/CodeBuild/ namespace in the Secrets Manager.

environment/registryCredential

Optional. ARegistryCredential object that specifies the credentials that provide access to a private Docker registry.

environment/registryCredential/credential

Specifies the ARN or name of credentials created using AWS Managed Services. You can use the name of the credentials only if they exist in your current Region.

environment/registryCredential/credentialProvider

The only valid value isSECRETS_MANAGER.

When this is set:

  • imagePullCredentials must be set toSERVICE_ROLE.

  • The image cannot be a curated image or an Amazon ECR image.

environment/imagePullCredentialsType

Optional. The type of credentials CodeBuild uses to pull images in your build. There are two valid values:

CODEBUILD

CODEBUILD specifies that CodeBuild uses its own credentials. You must edit your Amazon ECR repository policy to trust the CodeBuild service principal.

SERVICE_ROLE

Specifies that CodeBuild uses your build project's service role.

When you use a cross-account or private registry image, you must useSERVICE_ROLE credentials. When you use a CodeBuild curated image, you must useCODEBUILD credentials.

environment/privilegedMode

Set totrue only if you plan to use this build project to build Docker images. Otherwise, all associated builds that attempt to interact with the Docker daemon fail. You must also start the Docker daemon so that your builds can interact with it. One way to do this is to initialize the Docker daemon in theinstall phase of your buildspec file by running the following build commands. Do not run these commands if you specified a build environment image provided by CodeBuild with Docker support.

- nohup /usr/local/bin/dockerd --host=unix:///var/run/docker.sock --host=tcp://127.0.0.1:2375 --storage-driver=overlay2 &- timeout 15 sh -c "until docker info; do echo .; sleep 1; done"

serviceRole

Required. The ARN of the service role CodeBuild uses to interact with services on behalf of the user (for example,arn:aws:iam::account-id:role/role-name).

autoRetryLimit

Optional. The number of additional automatic retries after a failed build. For example, if the auto-retry limit is set to 2, CodeBuild will call theRetryBuild API to automatically retry your build for up to 2 additional times.

timeoutInMinutes

Optional. The number of minutes, between 5 to 2160 (36 hours), after which CodeBuild stops the build if it is not complete. If not specified, the default of 60 is used. To determine if and when CodeBuild stopped a build due to a timeout, run thebatch-get-builds command. To determine if the build has stopped, look in the output for abuildStatus value ofFAILED. To determine when the build timed out, look in the output for theendTime value associated with aphaseStatus value ofTIMED_OUT.

queuedTimeoutInMinutes

Optional. The number of minutes, between 5 to 480 (8 hours), after which CodeBuild stops the build if it is is still queued. If not specified, the default of 60 is used.

encryptionKey

Optional. The alias or ARN of the AWS KMS key used by CodeBuild to encrypt the build output. If you specify an alias, use the formatarn:aws:kms:region-ID:account-ID:key/key-ID or, if an alias exists, use the formatalias/key-alias. If not specified, the AWS-managed KMS key for Amazon S3 is used.

tags

Optional. An array ofTag objects that provide the tags you want to associate with this build project. You can specify up to 50 tags. These tags can be used by any AWS service that supports CodeBuild build project tags. Each tag is expressed as an object with akey and avalue.

vpcConfig

Optional. AVpcConfig object that contains information information about the VPC configuration for your project. For more information, seeUse AWS CodeBuild with Amazon Virtual Private Cloud.

These properties include:

badgeEnabled

Optional. Specifies whether to include build badges with your CodeBuild project. Set totrue to enable build badges, orfalse otherwise. For more information, seeBuild badges sample with CodeBuild.

logsConfig

ALogsConfig object that contains information about where this build's logs are located.

logsConfig/cloudWatchLogs

ACloudWatchLogsConfig object that contains information about pushing logs to CloudWatch Logs.

logsConfig/s3Logs

AnS3LogsConfig object that contains information about pushing logs to Amazon S3.

fileSystemLocations

Optional. An array ofProjectFileSystemsLocation objects that contains informationabout your Amazon EFS configuration.

buildBatchConfig

Optional. ThebuildBatchConfig object is aProjectBuildBatchConfig structure that contains the batch build configuration information for the project.

buildBatchConfig/serviceRole

The service role ARN for the batch build project.

buildBatchConfig/combineArtifacts

A Boolean value that specifies whether to combine the build artifacts for the batch build into a single artifact location.

buildBatchConfig/restrictions/maximumBuildsAllowed

The maximum number of builds allowed.

buildBatchConfig/restrictions/computeTypesAllowed

An array of strings that specify the compute types that are allowed for the batch build. SeeBuild environment compute types for these values.

buildBatchConfig/restrictions/fleetsAllowed

An array of strings that specify the fleets that are allowed for the batch build. SeeRun builds on reserved capacity fleets for more information.

buildBatchConfig/timeoutInMinutes

The maximum amount of time, in minutes, that the batch build must be completed in.

buildBatchConfig/batchReportMode

Specifies how build status reports are sent to the source provider for the batch build. Valid values include:

REPORT_AGGREGATED_BATCH

(Default) Aggregate all of the build statuses into a single status report.

REPORT_INDIVIDUAL_BUILDS

Send a separate status report for each individual build.

concurrentBuildLimit

The maximum number of concurrent builds that are allowed for this project.

New builds are only started if the current number of builds is less than or equal to this limit. If the current build count meets this limit, new builds are throttled and are not run.

Create the project

To create the project, run thecreate-project command again, passing your JSON file:

aws codebuild create-project --cli-input-json file://<json-file>

If successful, the JSON representation of aProject object appears in the console output. See theCreateProject Response Syntax for an example of this data.

Except for the build project name, you can change any of the build project's settings later. For more information, seeChange a build project's settings (AWS CLI).

To start running a build, seeRun a build (AWS CLI).

If your source code is stored in a GitHub repository, and you want CodeBuild to rebuild the source code every time a code change is pushed to the repository, seeStart running builds automatically (AWS CLI).

Create a build project (AWS SDKs)

For information about using AWS CodeBuild with the AWS SDKs, see theAWS SDKs and tools reference.

Create a build project (AWS CloudFormation)

For information about using AWS CodeBuild with AWS CloudFormation, seethe AWS CloudFormation template for CodeBuild in theAWS CloudFormation User Guide.

Build projects
Create a notification rule

[8]
ページ先頭

©2009-2025 Movatter.jp