Amazon SDK for JavaScript V3 API 参考指南详细描述了 Amazon SDK for JavaScript 版本 3 (V3) 的所有API操作。
本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
CodeBuild 使用 for JavaScript (v3) SDK 的示例
以下代码示例向您展示了如何通过使用 Amazon SDK for JavaScript (v3) 来执行操作和实现常见场景 CodeBuild。
操作是大型程序的代码摘录,必须在上下文中运行。您可以通过操作了解如何调用单个服务函数,还可以通过函数相关场景的上下文查看操作。
每个示例都包含一个指向完整源代码的链接,您可以在其中找到有关如何在上下文中设置和运行代码的说明。
主题
操作
以下代码示例显示了如何使用CreateProject
。
- SDK对于 JavaScript (v3)
-
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 Amazon 代码示例存储库
中进行设置和运行。 创建项目。
import { ArtifactsType, CodeBuildClient, ComputeType, CreateProjectCommand, EnvironmentType, SourceType, } from "@aws-sdk/client-codebuild"; // Create the AWS CodeBuild project. export const createProject = async ( projectName = "MyCodeBuilder", roleArn = "arn:aws:iam::xxxxxxxxxxxx:role/CodeBuildAdmin", buildOutputBucket = "xxxx", githubUrl = "https://...", ) => { const codeBuildClient = new CodeBuildClient({}); const response = await codeBuildClient.send( new CreateProjectCommand({ artifacts: { // The destination of the build artifacts. type: ArtifactsType.S3, location: buildOutputBucket, }, // Information about the build environment. The combination of "computeType" and "type" determines the // requirements for the environment such as CPU, memory, and disk space. environment: { // Build environment compute types. // https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-compute-types.html computeType: ComputeType.BUILD_GENERAL1_SMALL, // Docker image identifier. // See https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-available.html image: "aws/codebuild/standard:7.0", // Build environment type. type: EnvironmentType.LINUX_CONTAINER, }, name: projectName, // A role ARN with permission to create a CodeBuild project, write to the artifact location, and write CloudWatch logs. serviceRole: roleArn, source: { // The type of repository that contains the source code to be built. type: SourceType.GITHUB, // The location of the repository that contains the source code to be built. location: githubUrl, }, }), ); console.log(response); // { // '$metadata': { // httpStatusCode: 200, // requestId: 'b428b244-777b-49a6-a48d-5dffedced8e7', // extendedRequestId: undefined, // cfId: undefined, // attempts: 1, // totalRetryDelay: 0 // }, // project: { // arn: 'arn:aws:codebuild:us-east-1:xxxxxxxxxxxx:project/MyCodeBuilder', // artifacts: { // encryptionDisabled: false, // location: 'xxxxxx-xxxxxxx-xxxxxx', // name: 'MyCodeBuilder', // namespaceType: 'NONE', // packaging: 'NONE', // type: 'S3' // }, // badge: { badgeEnabled: false }, // cache: { type: 'NO_CACHE' }, // created: 2023-08-18T14:46:48.979Z, // encryptionKey: 'arn:aws:kms:us-east-1:xxxxxxxxxxxx:alias/aws/s3', // environment: { // computeType: 'BUILD_GENERAL1_SMALL', // environmentVariables: [], // image: 'aws/codebuild/standard:7.0', // imagePullCredentialsType: 'CODEBUILD', // privilegedMode: false, // type: 'LINUX_CONTAINER' // }, // lastModified: 2023-08-18T14:46:48.979Z, // name: 'MyCodeBuilder', // projectVisibility: 'PRIVATE', // queuedTimeoutInMinutes: 480, // serviceRole: 'arn:aws:iam::xxxxxxxxxxxx:role/CodeBuildAdmin', // source: { // insecureSsl: false, // location: 'https://...', // reportBuildStatus: false, // type: 'GITHUB' // }, // timeoutInMinutes: 60 // } // } return response; };
-
有关更多信息,请参阅 Amazon SDK for JavaScript 开发人员指南。
-
有关API详细信息,请参阅 “Amazon SDK for JavaScript API参考 CreateProject” 中的。
-