기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.
CodeBuild용 AWS CodePipeline 샘플
이 섹션에서는 CodePipeline과 CodeBuild 간의 샘플 통합에 대해 설명합니다.
Sample | 설명 |
---|---|
이 샘플은 AWS CodePipeline에서 배치 빌드를 사용하는 빌드 프로젝트를 생성하는 데 사용하는 방법을 보여 줍니다. |
|
이번 샘플에서는 AWS CodePipeline에서 다중 입력 소스를 사용해 다중 출력 결과물을 생성하는 빌드 프로젝트를 만드는 방법에 대해서 설명합니다. |
CodePipeline/CodeBuild 통합 및 배치 빌드 샘플
AWS CodeBuild에서는 배치 빌드를 지원합니다. 다음 샘플은 AWS CodePipeline에서 배치 빌드를 사용하는 빌드 프로젝트를 생성하는 데 사용하는 방법을 보여 줍니다.
파이프라인 구조를 정의하는 JSON 형식의 파일을 AWS CLI와 함께 사용하여 파이프라인을 만들 수 있습니다. 자세한 내용은 AWS CodePipeline 사용 설명서의 AWS CodePipeline 파이프라인 구조 참조를 참조하세요.
개별 아티팩트를 사용한 배치 빌드
다음 JSON 파일을 별도의 아티팩트가 있는 배치 빌드를 생성하는 파이프라인 구조의 예로 사용하세요. CodePipeline에서 배치 빌드를 활성화하려면 configuration
객체의 BatchEnabled
파라미터를 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": "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
파이프라인의 JSON 파일에서 지정하는 출력 아티팩트의 이름은 buildspec 파일에서 정의하는 빌드 및 아티팩트의 식별자와 일치해야 합니다. 구문은 기본 아티팩트의 경우 buildIdentifier
이고 보조 아티팩트의 경우 buildIdentifier
_artifactIdentifier
입니다.
예를 들어 출력 아티팩트 이름 build1
의 경우 CodeBuild는 build1
의 기본 아티팩트를 build1
의 위치에 업로드합니다. 출력 이름 build1_artifact1
의 경우 CodeBuild는 build1
의 보조 아티팩트 artifact1
을 build1_artifact1
위치에 업로드하는 방식으로 진행됩니다. 출력 위치를 하나만 지정하는 경우 이름은 buildIdentifier
입니다.
JSON 파일을 생성하였으면 이제 파이프라인을 만들 수 있습니다. AWS CLI에서 create-pipeline 명령을 실행한 후 파일을 --cli-input-json
파라미터로 전달합니다. 자세한 내용은 AWS CodePipeline 사용 설명서의 파이프라인 생성(CLI)을 참조하세요.
결합된 아티팩트를 사용한 배치 빌드
다음 JSON 파일을 결합된 아티팩트가 있는 배치 빌드를 생성하는 파이프라인 구조의 예로 사용하세요. CodePipeline에서 배치 빌드를 활성화하려면 configuration
객체의 BatchEnabled
파라미터를 true
로 설정합니다. 빌드 아티팩트를 같은 위치에 결합하려면 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
파라미터로 전달합니다. 자세한 내용은 AWS CodePipeline 사용 설명서의 파이프라인 생성(CLI)을 참조하세요.
CodePipeline/CodeBuild와 다중 입력 소스 및 출력 아티팩트 통합 샘플
AWS CodeBuild 프로젝트는 입력 소스가 여러 개 필요할 수 있습니다. 이에 따라 출력 아티팩트도 다수를 생성할 수 있습니다. 이번 샘플에서는 AWS CodePipeline에서 다중 입력 소스를 사용해 다중 출력 결과물을 생성하는 빌드 프로젝트를 만드는 방법에 대해서 설명합니다. 자세한 내용은 다중 입력 소스 및 출력 아티팩트 샘플 단원을 참조하십시오.
파이프라인 구조를 정의하는 JSON 형식의 파일을 AWS CLI와 함께 사용하여 파이프라인을 만들 수 있습니다. 다음 JSON 파일을 입력 소스 1개 이상과 출력 아티팩트 1개 이상을 사용해 빌드를 생성하는 파이프라인 구조의 예로 사용합니다. 이번 샘플 후반에서 이 파일이 다중 입력 및 출력을 어떻게 지정하는지 확인할 수 있습니다. 자세한 내용은 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
는 JSON 파일 CodeBuild 단계의configuration
섹션에서 기본 소스를 지정하는 데 사용됩니다. -
각 입력 소스는 자체 디렉터리에 설치됩니다. 이 디렉터리는 기본 소스의 경우 기본 제공 환경 변수
$CODEBUILD_SRC_DIR
에, 기타 모든 소스의 경우$CODEBUILD_SRC_DIR_yourInputArtifactName
에 저장됩니다. 위 샘플의 파이프라인에서는 2개의 입력 소스 디렉터리가$CODEBUILD_SRC_DIR
과$CODEBUILD_SRC_DIR_source2
입니다. 자세한 내용은 빌드 환경의 환경 변수 단원을 참조하십시오. -
파이프라인의 JSON 파일에서 지정하는 출력 아티팩트의 이름은 buildspec 파일에서 정의하는 보조 아티팩트의 이름과 일치해야 합니다. 이 파이프라인에서 사용하는 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
파라미터로 전달합니다. 자세한 내용은 AWS CodePipeline 사용 설명서의 파이프라인 생성(CLI)을 참조하세요.