本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
使用下列程序來建立具有多個輸入和輸出的建置專案。
若要建立具有多個輸入和輸出的建置專案
-
將您的來源上傳到一或多個 S3 儲存貯體 CodeCommit、 GitHub、 GitHub 企業伺服器或 Bitbucket 儲存庫。
-
選擇哪個來源是主要來源。這是查 CodeBuild 找並運行構建規格文件的源代碼。
-
建立建置專案。如需詳細資訊,請參閱在 中建立建置專案 AWS CodeBuild。
-
創建您的構建項目,運行構建,並獲取有關構建的信息。
-
如果您使 AWS CLI 用建立組建專案,
create-project
指令的 JSON-格式輸入可能類似於下列內容:{ "name": "sample-project", "source": { "type": "S3", "location": "
<bucket/sample.zip>
" }, "secondarySources": [ { "type": "CODECOMMIT", "location": "https://git-codecommit.us-west-2.amazonaws.com/v1/repos/repo", "sourceIdentifier": "source1" }, { "type": "GITHUB", "location": "https://github.com/awslabs/aws-codebuild-jenkins-plugin", "sourceIdentifier": "source2" } ], "secondaryArtifacts": [ss { "type": "S3", "location": "<output-bucket>
", "artifactIdentifier": "artifact1" }, { "type": "S3", "location": "<other-output-bucket>
", "artifactIdentifier": "artifact2" } ], "environment": { "type": "LINUX_CONTAINER", "image": "aws/codebuild/standard:5.0", "computeType": "BUILD_GENERAL1_SMALL" }, "serviceRole": "arn:aws:iam::account-ID:role/role-name", "encryptionKey": "arn:aws:kms:region-ID:account-ID:key/key-ID" }
您的主要來源是在 source
屬性下方定義。其他所有來源稱為次要來源,出現在 secondarySources
下方。所有次要來源安裝在其自己的目錄中。此目錄存放在內建環境變數 CODEBUILD_SRC_DIR_
中。如需詳細資訊,請參閱建置環境中的環境變數。sourceIdentifer
secondaryArtifacts
屬性包含成品定義清單。這些成品使用 buildspec 檔案的 secondary-artifacts
區塊 (巢狀於 artifacts
區塊內)。
buildspec 檔案中的次要成品具有與成品相同的結構,且依成品識別符區隔。
注意
在中 CodeBuild API,在次要加工品artifactIdentifier
上是和中的必要屬CreateProject
性UpdateProject
。必須用來參考次要成品。
使用前面的JSON格式化輸入,項目的 buildspec 文件可能如下所示:
version: 0.2
phases:
install:
runtime-versions:
java: openjdk11
build:
commands:
- cd $CODEBUILD_SRC_DIR_source1
- touch file1
- cd $CODEBUILD_SRC_DIR_source2
- touch file2
artifacts:
files:
- '**.*'
secondary-artifacts:
artifact1:
base-directory: $CODEBUILD_SRC_DIR_source1
files:
- file1
artifact2:
base-directory: $CODEBUILD_SRC_DIR_source2
files:
- file2
您可以使用中的sourceVersion
屬性覆寫主要API來源的版本StartBuild
。若要覆寫一個或多個次要來源版本,請使用 secondarySourceVersionOverride
屬性。
中start-build
指令的JSON格式化輸入 AWS CLI 可能如下所示:
{
"projectName": "sample-project",
"secondarySourcesVersionOverride": [
{
"sourceIdentifier": "source1",
"sourceVersion": "codecommit-branch"
},
{
"sourceIdentifier": "source2",
"sourceVersion": "github-branch"
},
]
}