CodePipeline 샘플: CodeBuild - AWS CodeBuild

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

CodePipeline 샘플: CodeBuild

AWS CodePipeline 통합 CodeBuild 및 일괄 빌드

AWS CodeBuild 이제 일괄 빌드를 지원합니다. 이 샘플은 배치 빌드를 사용하는 빌드 프로젝트를 만드는 AWS CodePipeline 데 사용하는 방법을 보여줍니다.

파이프라인의 구조를 정의하는 JSON -formatted 파일을 사용한 다음, 와 함께 사용하여 파이프라인을 생성할 수 있습니다. AWS CLI 자세한 내용은AWS CodePipeline 사용 설명서의 AWS CodePipeline 파이프라인 구조 참조를 참조하세요.

개별 아티팩트를 사용한 배치 빌드

다음 JSON 파일을 별도의 아티팩트가 있는 배치 빌드를 생성하는 파이프라인 구조의 예로 사용하세요. 일괄 빌드를 활성화하려면 configuration true 객체의 BatchEnabled 파라미터를 로 설정합니다. CodePipeline

{ "pipeline": { "roleArn": "arn:aws:iam::account-id:role/my-AWS-CodePipeline-service-role-name", "stages": [ { "name": "Source", "actions": [ { "inputArtifacts": [], "name": "Source1", "actionTypeId": { "category": "Source", "owner": "AWS", "version": "1", "provider": "S3" }, "outputArtifacts": [ { "name": "source1" } ], "configuration": { "S3Bucket": "<my-input-bucket-name>", "S3ObjectKey": "my-source-code-file-name.zip" }, "runOrder": 1 }, { "inputArtifacts": [], "name": "Source2", "actionTypeId": { "category": "Source", "owner": "AWS", "version": "1", "provider": "S3" }, "outputArtifacts": [ { "name": "source2" } ], "configuration": { "S3Bucket": "<my-other-input-bucket-name>", "S3ObjectKey": "my-other-source-code-file-name.zip" }, "runOrder": 1 } ] }, { "name": "Build", "actions": [ { "inputArtifacts": [ { "name": "source1" }, { "name": "source2" } ], "name": "Build", "actionTypeId": { "category": "Build", "owner": "AWS", "version": "1", "provider": "CodeBuild" }, "outputArtifacts": [ { "name": "build1" }, { "name": "build1_artifact1" }, { "name": "build1_artifact2" }, { "name": "build2_artifact1" }, { "name": "build2_artifact2" } ], "configuration": { "ProjectName": "my-build-project-name", "PrimarySource": "source1", "BatchEnabled": "true" }, "runOrder": 1 } ] } ], "artifactStore": { "type": "S3", "location": "<AWS-CodePipeline-internal-bucket-name>" }, "name": "my-pipeline-name", "version": 1 } }

다음은 이 파이프라인 구성과 함께 사용할 수 있는 CodeBuild buildspec 파일의 예제입니다.

version: 0.2 batch: build-list: - identifier: build1 env: compute-type: BUILD_GENERAL1_SMALL - identifier: build2 env: compute-type: BUILD_GENERAL1_MEDIUM phases: build: commands: - echo 'file' > output_file artifacts: files: - output_file secondary-artifacts: artifact1: files: - output_file artifact2: files: - output_file

파이프라인 파일에 지정된 출력 아티팩트의 이름은 buildspec JSON 파일에 정의된 빌드 및 아티팩트의 식별자와 일치해야 합니다. 구문은 다음과 같습니다.buildIdentifier 기본 아티팩트의 경우,buildIdentifier_artifactIdentifier 보조 아티팩트의 경우.

예를 들어 출력 아티팩트 이름의 build1 CodeBuild 경우 기본 build1 아티팩트를 의 위치에 업로드합니다. build1 출력 이름의 build1_artifact1 CodeBuild 경우 보조 build1 아티팩트를 artifact1 위치 build1_artifact1 등에 업로드합니다. 출력 위치를 하나만 지정하는 경우 이름은 다음과 같아야 합니다.buildIdentifier 전용.

JSON파일을 생성한 후 파이프라인을 생성할 수 있습니다. AWS CLI 를 사용하여 create-pipeline 명령을 실행하고 파일을 파라미터에 전달합니다. --cli-input-json 자세한 내용은 사용 안내서의 파이프라인 만들기 (CLI) 를AWS CodePipeline 참조하십시오.

결합된 아티팩트를 사용한 배치 빌드

다음 JSON 파일을 아티팩트가 결합된 배치 빌드를 만드는 파이프라인 구조의 예로 사용하세요. 일괄 빌드를 활성화하려면 configuration true 객체의 BatchEnabled 파라미터를 로 설정합니다. CodePipeline 빌드 아티팩트를 같은 위치에 결합하려면 configuration 객체의 CombineArtifacts 파라미터를 true로 설정합니다.

{ "pipeline": { "roleArn": "arn:aws:iam::account-id:role/my-AWS-CodePipeline-service-role-name", "stages": [ { "name": "Source", "actions": [ { "inputArtifacts": [], "name": "Source1", "actionTypeId": { "category": "Source", "owner": "AWS", "version": "1", "provider": "S3" }, "outputArtifacts": [ { "name": "source1" } ], "configuration": { "S3Bucket": "<my-input-bucket-name>", "S3ObjectKey": "my-source-code-file-name.zip" }, "runOrder": 1 }, { "inputArtifacts": [], "name": "Source2", "actionTypeId": { "category": "Source", "owner": "AWS", "version": "1", "provider": "S3" }, "outputArtifacts": [ { "name": "source2" } ], "configuration": { "S3Bucket": "<my-other-input-bucket-name>", "S3ObjectKey": "my-other-source-code-file-name.zip" }, "runOrder": 1 } ] }, { "name": "Build", "actions": [ { "inputArtifacts": [ { "name": "source1" }, { "name": "source2" } ], "name": "Build", "actionTypeId": { "category": "Build", "owner": "AWS", "version": "1", "provider": "CodeBuild" }, "outputArtifacts": [ { "name": "output1 " } ], "configuration": { "ProjectName": "my-build-project-name", "PrimarySource": "source1", "BatchEnabled": "true", "CombineArtifacts": "true" }, "runOrder": 1 } ] } ], "artifactStore": { "type": "S3", "location": "<AWS-CodePipeline-internal-bucket-name>" }, "name": "my-pipeline-name", "version": 1 } }

다음은 이 파이프라인 구성과 함께 사용할 수 있는 CodeBuild buildspec 파일의 예제입니다.

version: 0.2 batch: build-list: - identifier: build1 env: compute-type: BUILD_GENERAL1_SMALL - identifier: build2 env: compute-type: BUILD_GENERAL1_MEDIUM phases: build: commands: - echo 'file' > output_file artifacts: files: - output_file

결합 아티팩트가 배치 빌드에 활성화된 경우 출력은 하나만 허용됩니다. CodeBuild 모든 빌드의 기본 아티팩트를 하나의 ZIP 파일로 결합합니다.

JSON파일을 생성한 후 파이프라인을 생성할 수 있습니다. AWS CLI 를 사용하여 create-pipeline 명령을 실행하고 파일을 파라미터에 전달합니다. --cli-input-json 자세한 내용은 사용 안내서의 파이프라인 만들기 (CLI) 를AWS CodePipeline 참조하십시오.

AWS CodePipeline 여러 입력 소스 CodeBuild 및 출력 아티팩트와의 통합 샘플

AWS CodeBuild 프로젝트는 입력 소스를 두 개 이상 사용할 수 있습니다. 이에 따라 출력 아티팩트도 다수를 생성할 수 있습니다. 이 샘플은 여러 입력 소스를 AWS CodePipeline 사용하여 여러 출력 아티팩트를 만드는 빌드 프로젝트를 만드는 데 사용하는 방법을 보여줍니다. 자세한 내용은 다중 입력 소스 및 출력 아티팩트 샘플 단원을 참조하십시오.

파이프라인의 구조를 정의하는 JSON -formatted 파일을 사용한 다음, 와 함께 사용하여 파이프라인을 생성할 수 있습니다. AWS CLI 다음 JSON 파일을 둘 이상의 입력 소스와 둘 이상의 출력 아티팩트가 있는 빌드를 만드는 파이프라인 구조의 예로 사용하세요. 이번 샘플 후반에서 이 파일이 다중 입력 및 출력을 어떻게 지정하는지 확인할 수 있습니다. 자세한 내용은 AWS CodePipeline 사용 설명서의 CodePipeline 파이프라인 구조 참조를 참조하십시오.

{ "pipeline": { "roleArn": "arn:aws:iam::account-id:role/my-AWS-CodePipeline-service-role-name", "stages": [ { "name": "Source", "actions": [ { "inputArtifacts": [], "name": "Source1", "actionTypeId": { "category": "Source", "owner": "AWS", "version": "1", "provider": "S3" }, "outputArtifacts": [ { "name": "source1" } ], "configuration": { "S3Bucket": "my-input-bucket-name", "S3ObjectKey": "my-source-code-file-name.zip" }, "runOrder": 1 }, { "inputArtifacts": [], "name": "Source2", "actionTypeId": { "category": "Source", "owner": "AWS", "version": "1", "provider": "S3" }, "outputArtifacts": [ { "name": "source2" } ], "configuration": { "S3Bucket": "my-other-input-bucket-name", "S3ObjectKey": "my-other-source-code-file-name.zip" }, "runOrder": 1 } ] }, { "name": "Build", "actions": [ { "inputArtifacts": [ { "name": "source1" }, { "name": "source2" } ], "name": "Build", "actionTypeId": { "category": "Build", "owner": "AWS", "version": "1", "provider": "AWS CodeBuild" }, "outputArtifacts": [ { "name": "artifact1" }, { "name": "artifact2" } ], "configuration": { "ProjectName": "my-build-project-name", "PrimarySource": "source1" }, "runOrder": 1 } ] } ], "artifactStore": { "type": "S3", "location": "AWS-CodePipeline-internal-bucket-name" }, "name": "my-pipeline-name", "version": 1 } }

이 JSON 파일에서:

  • 입력 소스 중 하나는 PrimarySource로 지정되어야 합니다. 이 소스는 CodeBuild buildspec 파일을 찾아 실행하는 디렉토리입니다. PrimarySource키워드는 파일의 CodeBuild 스테이지 configuration 섹션에 기본 소스를 지정하는 데 사용됩니다. JSON

  • 각 입력 소스는 자체 디렉터리에 설치됩니다. 이 디렉터리는 기본 소스의 경우 기본 제공 환경 변수 $CODEBUILD_SRC_DIR에, 기타 모든 소스의 경우 $CODEBUILD_SRC_DIR_yourInputArtifactName에 저장됩니다. 위 샘플의 파이프라인에서는 2개의 입력 소스 디렉터리가 $CODEBUILD_SRC_DIR$CODEBUILD_SRC_DIR_source2입니다. 자세한 내용은 빌드 환경의 환경 변수 단원을 참조하십시오.

  • 파이프라인 파일에 지정된 출력 아티팩트의 이름은 buildspec JSON 파일에 정의된 보조 아티팩트의 이름과 일치해야 합니다. 이 파이프라인에서 사용하는 buildspec 파일은 다음과 같습니다. 자세한 내용은 buildspec 구문 단원을 참조하십시오.

    version: 0.2 phases: build: commands: - touch source1_file - cd $CODEBUILD_SRC_DIR_source2 - touch source2_file artifacts: files: - '**/*' secondary-artifacts: artifact1: base-directory: $CODEBUILD_SRC_DIR files: - source1_file artifact2: base-directory: $CODEBUILD_SRC_DIR_source2 files: - source2_file

JSON파일을 생성한 후 파이프라인을 생성할 수 있습니다. AWS CLI 를 사용하여 create-pipeline 명령을 실행하고 파일을 파라미터에 전달합니다. --cli-input-json 자세한 내용은 사용 안내서의 파이프라인 만들기 (CLI) 를AWS CodePipeline 참조하십시오.