CodePipeline 使用 的範例 AWS CLI - AWS Command Line Interface

本文件 AWS CLI 僅適用於 的第 1 版。如需與 第 2 版相關的文件 AWS CLI,請參閱 第 2 版使用者指南

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

CodePipeline 使用 的範例 AWS CLI

下列程式碼範例示範如何使用 AWS Command Line Interface 搭配 來執行動作和實作常見案例 CodePipeline。

Actions 是大型程式的程式碼摘錄,必須在內容中執行。雖然動作會示範如何呼叫個別服務函數,但您可以在相關案例中查看內容中的動作。

每個範例都包含完整原始程式碼的連結,您可以在其中找到如何在內容中設定和執行程式碼的指示。

主題

動作

下列程式碼範例示範如何使用 acknowledge-job

AWS CLI

擷取指定任務的相關資訊

此範例會傳回指定任務的相關資訊,包括該任務存在時的狀態。這僅用於作業工作者和自訂動作。若要判斷 nonce 和任務 ID 的值,請使用 aws Codepipeline poll-for-jobs。

命令:

aws codepipeline acknowledge-job --job-id f4f4ff82-2d11-EXAMPLE --nonce 3

輸出:

{ "status": "InProgress" }
  • 如需API詳細資訊,請參閱 命令參考 AcknowledgeJob中的 。 AWS CLI

下列程式碼範例示範如何使用 create-custom-action-type

AWS CLI

若要建立自訂動作

此範例會建立自訂動作,以 AWS CodePipeline 使用已建立且包含自訂動作結構JSON的檔案 (此處名為 MyCustomAction.json)。如需建立自訂動作要求的詳細資訊,包括 檔案的結構,請參閱 AWS CodePipeline 使用者指南。

aws codepipeline create-custom-action-type --cli-input-json file://MyCustomAction.json

JSON 檔案 的內容MyCustomAction.json

{ "category": "Build", "provider": "MyJenkinsProviderName", "version": "1", "settings": { "entityUrlTemplate": "https://192.0.2.4/job/{Config:ProjectName}/", "executionUrlTemplate": "https://192.0.2.4/job/{Config:ProjectName}/lastSuccessfulBuild/{ExternalExecutionId}/" }, "configurationProperties": [ { "name": "MyJenkinsExampleBuildProject", "required": true, "key": true, "secret": false, "queryable": false, "description": "The name of the build project must be provided when this action is added to the pipeline.", "type": "String" } ], "inputArtifactDetails": { "maximumCount": 1, "minimumCount": 0 }, "outputArtifactDetails": { "maximumCount": 1, "minimumCount": 0 } }

此命令會傳回自訂動作的結構。

下列程式碼範例示範如何使用 create-pipeline

AWS CLI

建立管道

此範例 AWS CodePipeline 使用已建立JSON的檔案 (此處名為 MySecondPipeline.json) 在 中建立管道,其中包含管道的結構。如需建立管道需求的詳細資訊,包括 檔案的結構,請參閱 AWS CodePipeline 使用者指南。

命令:

aws codepipeline create-pipeline --cli-input-json file://MySecondPipeline.json

JSON 檔案範例內容:

{ "pipeline": { "roleArn": "arn:aws:iam::111111111111:role/AWS-CodePipeline-Service", "stages": [ { "name": "Source", "actions": [ { "inputArtifacts": [], "name": "Source", "actionTypeId": { "category": "Source", "owner": "AWS", "version": "1", "provider": "S3" }, "outputArtifacts": [ { "name": "MyApp" } ], "configuration": { "S3Bucket": "awscodepipeline-demo-bucket", "S3ObjectKey": "aws-codepipeline-s3-aws-codedeploy_linux.zip" }, "runOrder": 1 } ] }, { "name": "Beta", "actions": [ { "inputArtifacts": [ { "name": "MyApp" } ], "name": "CodePipelineDemoFleet", "actionTypeId": { "category": "Deploy", "owner": "AWS", "version": "1", "provider": "CodeDeploy" }, "outputArtifacts": [], "configuration": { "ApplicationName": "CodePipelineDemoApplication", "DeploymentGroupName": "CodePipelineDemoFleet" }, "runOrder": 1 } ] } ], "artifactStore": { "type": "S3", "location": "codepipeline-us-east-1-11EXAMPLE11" }, "name": "MySecondPipeline", "version": 1 } }

輸出:

This command returns the structure of the pipeline.
  • 如需API詳細資訊,請參閱 命令參考 CreatePipeline中的 。 AWS CLI

下列程式碼範例示範如何使用 delete-custom-action-type

AWS CLI

若要刪除自訂動作

此範例 AWS CodePipeline 使用已建立JSON的檔案 (此處名為 DeleteMyCustomAction.json) 刪除 中的自訂動作,其中包含要刪除的動作類型、提供者名稱和版本編號。使用 list-action-types命令來檢視類別、版本和提供者的正確值。

命令:

aws codepipeline delete-custom-action-type --cli-input-json file://DeleteMyCustomAction.json

JSON 檔案範例內容:

{ "category": "Build", "version": "1", "provider": "MyJenkinsProviderName" }

輸出:

None.

下列程式碼範例示範如何使用 delete-pipeline

AWS CLI

刪除管道

此範例 MySecondPipeline 會從 刪除名為 的管道 AWS CodePipeline。使用 list-pipelines 命令來檢視與 AWS 您的帳戶相關聯的管道清單。

命令:

aws codepipeline delete-pipeline --name MySecondPipeline

輸出:

None.
  • 如需API詳細資訊,請參閱 命令參考 DeletePipeline中的 。 AWS CLI

下列程式碼範例示範如何使用 delete-webhook

AWS CLI

刪除 Webhook

下列delete-webhook範例會刪除第 1 GitHub 版來源動作的 Webhook。刪除 Webhook 之前,您必須使用 deregister-webhook-with-third-party命令取消註冊。

aws codepipeline delete-webhook \ --name my-webhook

此命令不會產生輸出。

如需詳細資訊,請參閱 AWS CodePipeline 使用者指南 中的刪除 GitHub 來源的 Webhook

  • 如需API詳細資訊,請參閱 命令參考 DeleteWebhook中的 。 AWS CLI

下列程式碼範例示範如何使用 deregister-webhook-with-third-party

AWS CLI

若要取消註冊 Webhook

下列deregister-webhook-with-third-party範例會刪除第 1 GitHub 版來源動作的 Webhook。您必須先取消註冊 Webhook,然後才能將其刪除。

aws codepipeline deregister-webhook-with-third-party \ --webhook-name my-webhook

此命令不會產生輸出。

如需詳細資訊,請參閱 AWS CodePipeline 使用者指南 中的刪除 GitHub 來源的 Webhook

下列程式碼範例示範如何使用 disable-stage-transition

AWS CLI

停用轉換至管道中的階段

此範例會停用轉換至 中 MyFirstPipeline 管道的 Beta 階段 AWS CodePipeline。

命令:

aws codepipeline disable-stage-transition --pipeline-name MyFirstPipeline --stage-name Beta --transition-type Inbound

輸出:

None.

下列程式碼範例示範如何使用 enable-stage-transition

AWS CLI

若要啟用轉換至管道中的階段

此範例可讓 轉換至 中 MyFirstPipeline 管道的 Beta 階段 AWS CodePipeline。

命令:

aws codepipeline enable-stage-transition --pipeline-name MyFirstPipeline --stage-name Beta --transition-type Inbound

輸出:

None.

下列程式碼範例示範如何使用 get-job-details

AWS CLI

若要取得任務的詳細資訊

此範例會傳回 ID 由 f4f4ff82-2d11- 表示之任務的詳細資訊EXAMPLE。此命令僅用於自訂動作。呼叫此命令時, 會 AWS CodePipeline 傳回用於儲存管道成品的 Amazon S3 儲存貯體的臨時憑證,如果自訂動作需要的話。如果定義了任何秘密值,此命令也會傳回為動作定義的任何秘密值。

命令:

aws codepipeline get-job-details --job-id f4f4ff82-2d11-EXAMPLE

輸出:

{ "jobDetails": { "accountId": "111111111111", "data": { "actionConfiguration": { "__type": "ActionConfiguration", "configuration": { "ProjectName": "MyJenkinsExampleTestProject" } }, "actionTypeId": { "__type": "ActionTypeId", "category": "Test", "owner": "Custom", "provider": "MyJenkinsProviderName", "version": "1" }, "artifactCredentials": { "__type": "AWSSessionCredentials", "accessKeyId": "AKIAIOSFODNN7EXAMPLE", "secretAccessKey": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY", "sessionToken": "fICCQD6m7oRw0uXOjANBgkqhkiG9w0BAQUFADCBiDELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAldBMRAwDgYDVQQHEwdTZWF0dGxlMQ8wDQYDVQQKEwZBbWF6b24xFDASBgNVBAsTC0lBTSBDb25zb2xlMRIwEAYDVQQDEwlUZXN0Q2lsYWMxHzAdBgkqhkiG9w0BCQEWEG5vb25lQGFtYXpvbi5jb20wHhcNMTEwNDI1MjA0NTIxWhcNMTIwNDI0MjA0NTIxWjCBiDELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAldBMRAwDgYDVQQHEwdTZWF0dGxlMQ8wDQYDVQQKEwZBbWF6b24xFDASBgNVBAsTC0lBTSBDb25zb2xlMRIwEAYDVQQDEwlUZXN0Q2lsYWMxHzAdBgkqhkiG9w0BCQEWEG5vb25lQGFtYXpvbi5jb20wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAMaK0dn+a4GmWIWJ21uUSfwfEvySWtC2XADZ4nB+BLYgVIk60CpiwsZ3G93vUEIO3IyNoH/f0wYK8m9TrDHudUZg3qX4waLG5M43q7Wgc/MbQITxOUSQv7c7ugFFDzQGBzZswY6786m86gpEIbb3OhjZnzcvQAaRHhdlQWIMm2nrAgMBAAEwDQYJKoZIhvcNAQEFBQADgYEAtCu4nUhVVxYUntneD9+h8Mg9q6q+auNKyExzyLwaxlAoo7TJHidbtS4J5iNmZgXL0FkbFFBjvSfpJIlJ00zbhNYS5f6GuoEDmFJl0ZxBHjJnyp378OD8uTs7fLvjx79LjSTbNYiytVbZPQUQ5Yaxu2jXnimvw3rrszlaEXAMPLE=" }, "inputArtifacts": [ { "__type": "Artifact", "location": { "s3Location": { "bucketName": "codepipeline-us-east-1-11EXAMPLE11", "objectKey": "MySecondPipeline/MyAppBuild/EXAMPLE" }, "type": "S3" }, "name": "MyAppBuild" } ], "outputArtifacts": [], "pipelineContext": { "__type": "PipelineContext", "action": { "name": "MyJenkinsTest-Action" }, "pipelineName": "MySecondPipeline", "stage": { "name": "Testing" } } }, "id": "f4f4ff82-2d11-EXAMPLE" } }
  • 如需API詳細資訊,請參閱 命令參考 GetJobDetails中的 。 AWS CLI

下列程式碼範例示範如何使用 get-pipeline-state

AWS CLI

取得管道狀態的相關資訊

此範例會傳回名為 之管道的最新狀態 MyFirstPipeline。

命令:

aws codepipeline get-pipeline-state --name MyFirstPipeline

輸出:

{ "created": 1446137312.204, "pipelineName": "MyFirstPipeline", "pipelineVersion": 1, "stageStates": [ { "actionStates": [ { "actionName": "Source", "entityUrl": "https://console.aws.amazon.com/s3/home?#", "latestExecution": { "lastStatusChange": 1446137358.328, "status": "Succeeded" } } ], "stageName": "Source" }, { "actionStates": [ { "actionName": "CodePipelineDemoFleet", "entityUrl": "https://console.aws.amazon.com/codedeploy/home?#/applications/CodePipelineDemoApplication/deployment-groups/CodePipelineDemoFleet", "latestExecution": { "externalExecutionId": "d-EXAMPLE", "externalExecutionUrl": "https://console.aws.amazon.com/codedeploy/home?#/deployments/d-EXAMPLE", "lastStatusChange": 1446137493.131, "status": "Succeeded", "summary": "Deployment Succeeded" } } ], "inboundTransitionState": { "enabled": true }, "stageName": "Beta" } ], "updated": 1446137312.204 }
  • 如需API詳細資訊,請參閱 命令參考 GetPipelineState中的 。 AWS CLI

下列程式碼範例示範如何使用 get-pipeline

AWS CLI

檢視管道的結構

此範例會傳回名為 的管道結構 MyFirstPipeline。

命令:

aws codepipeline get-pipeline --name MyFirstPipeline

輸出:

{ "pipeline": { "roleArn": "arn:aws:iam::111111111111:role/AWS-CodePipeline-Service", "stages": [ { "name": "Source", "actions": [ { "inputArtifacts": [], "name": "Source", "actionTypeId": { "category": "Source", "owner": "AWS", "version": "1", "provider": "S3" }, "outputArtifacts": [ { "name": "MyApp" } ], "configuration": { "S3Bucket": "awscodepipeline-demo-bucket", "S3ObjectKey": "aws-codepipeline-s3-aws-codedeploy_linux.zip" }, "runOrder": 1 } ] }, { "name": "Beta", "actions": [ { "inputArtifacts": [ { "name": "MyApp" } ], "name": "CodePipelineDemoFleet", "actionTypeId": { "category": "Deploy", "owner": "AWS", "version": "1", "provider": "CodeDeploy" }, "outputArtifacts": [], "configuration": { "ApplicationName": "CodePipelineDemoApplication", "DeploymentGroupName": "CodePipelineDemoFleet" }, "runOrder": 1 } ] } ], "artifactStore": { "type": "S3", "location": "codepipeline-us-east-1-11EXAMPLE11" }, "name": "MyFirstPipeline", "version": 1 } }
  • 如需API詳細資訊,請參閱 命令參考 GetPipeline中的 。 AWS CLI

下列程式碼範例示範如何使用 list-action-executions

AWS CLI

列出動作執行

下列list-action-executions範例會檢視管道的動作執行詳細資訊,例如動作執行 ID、輸入成品、輸出成品、執行結果和狀態。

aws codepipeline list-action-executions \ --pipeline-name myPipeline

輸出:

{ "actionExecutionDetails": [ { "pipelineExecutionId": "EXAMPLE0-adfc-488e-bf4c-1111111720d3", "actionExecutionId": "EXAMPLE4-2ee8-4853-bd6a-111111158148", "pipelineVersion": 12, "stageName": "Deploy", "actionName": "Deploy", "startTime": 1598572628.6, "lastUpdateTime": 1598572661.255, "status": "Succeeded", "input": { "actionTypeId": { "category": "Deploy", "owner": "AWS", "provider": "CodeDeploy", "version": "1" }, "configuration": { "ApplicationName": "my-application", "DeploymentGroupName": "my-deployment-group" }, "resolvedConfiguration": { "ApplicationName": "my-application", "DeploymentGroupName": "my-deployment-group" }, "region": "us-east-1", "inputArtifacts": [ { "name": "SourceArtifact", "s3location": { "bucket": "artifact-bucket", "key": "myPipeline/SourceArti/key" } } ], "namespace": "DeployVariables" }, "output": { "outputArtifacts": [], "executionResult": { "externalExecutionId": "d-EXAMPLEE5", "externalExecutionSummary": "Deployment Succeeded", "externalExecutionUrl": "https://myaddress.com" }, "outputVariables": {} } }, { "pipelineExecutionId": "EXAMPLE0-adfc-488e-bf4c-1111111720d3", "actionExecutionId": "EXAMPLE5-abb4-4192-9031-11111113a7b0", "pipelineVersion": 12, "stageName": "Source", "actionName": "Source", "startTime": 1598572624.387, "lastUpdateTime": 1598572628.16, "status": "Succeeded", "input": { "actionTypeId": { "category": "Source", "owner": "AWS", "provider": "CodeCommit", "version": "1" }, "configuration": { "BranchName": "production", "PollForSourceChanges": "false", "RepositoryName": "my-repo" }, "resolvedConfiguration": { "BranchName": "production", "PollForSourceChanges": "false", "RepositoryName": "my-repo" }, "region": "us-east-1", "inputArtifacts": [], "namespace": "SourceVariables" }, "output": { "outputArtifacts": [ { "name": "SourceArtifact", "s3location": { "bucket": "my-bucket", "key": "myPipeline/SourceArti/key" } } ], "executionResult": { "externalExecutionId": "1111111ad99dcd35914c00b7fbea13995EXAMPLE", "externalExecutionSummary": "Edited template.yml", "externalExecutionUrl": "https://myaddress.com" }, "outputVariables": { "AuthorDate": "2020-05-08T17:45:43Z", "BranchName": "production", "CommitId": "EXAMPLEad99dcd35914c00b7fbea139951111111", "CommitMessage": "Edited template.yml", "CommitterDate": "2020-05-08T17:45:43Z", "RepositoryName": "my-repo" } } }, . . . .

如需詳細資訊,請參閱 AWS CodePipeline 使用者指南 中的檢視動作執行 (CLI)

下列程式碼範例示範如何使用 list-action-types

AWS CLI

檢視可用的動作類型

命令會自行 list-action-types傳回 AWS 帳戶可用的所有動作結構。此範例使用 --action-owner-filter option 僅傳回自訂動作。

命令:

aws codepipeline list-action-types --action-owner-filter Custom

輸出:

{ "actionTypes": [ { "inputArtifactDetails": { "maximumCount": 5, "minimumCount": 0 }, "actionConfigurationProperties": [ { "secret": false, "required": true, "name": "MyJenkinsExampleBuildProject", "key": true, "queryable": true } ], "outputArtifactDetails": { "maximumCount": 5, "minimumCount": 0 }, "id": { "category": "Build", "owner": "Custom", "version": "1", "provider": "MyJenkinsProviderName" }, "settings": { "entityUrlTemplate": "http://192.0.2.4/job/{Config:ProjectName}", "executionUrlTemplate": "http://192.0.2.4/job/{Config:ProjectName}/{ExternalExecutionId}" } }, { "inputArtifactDetails": { "maximumCount": 5, "minimumCount": 0 }, "actionConfigurationProperties": [ { "secret": false, "required": true, "name": "MyJenkinsExampleTestProject", "key": true, "queryable": true } ], "outputArtifactDetails": { "maximumCount": 5, "minimumCount": 0 }, "id": { "category": "Test", "owner": "Custom", "version": "1", "provider": "MyJenkinsProviderName" }, "settings": { "entityUrlTemplate": "http://192.0.2.4/job/{Config:ProjectName}", "executionUrlTemplate": "http://192.0.2.4/job/{Config:ProjectName}/{ExternalExecutionId}" } } ] }
  • 如需API詳細資訊,請參閱 命令參考 ListActionTypes中的 。 AWS CLI

下列程式碼範例示範如何使用 list-pipeline-executions

AWS CLI

檢視管道執行歷史記錄

下列list-pipeline-executions範例顯示您 AWS 帳戶中管道的管道執行歷史記錄。

aws codepipeline list-pipeline-executions \ --pipeline-name MyPipeline

輸出:

{ "pipelineExecutionSummaries": [ { "lastUpdateTime": 1496380678.648, "pipelineExecutionId": "7cf7f7cb-3137-539g-j458-d7eu3EXAMPLE", "startTime": 1496380258.243, "status": "Succeeded" }, { "lastUpdateTime": 1496591045.634, "pipelineExecutionId": "3137f7cb-8d494hj4-039j-d84l-d7eu3EXAMPLE", "startTime": 1496590401.222, "status": "Succeeded" }, { "lastUpdateTime": 1496946071.6456, "pipelineExecutionId": "4992f7jf-7cf7-913k-k334-d7eu3EXAMPLE", "startTime": 1496945471.5645, "status": "Succeeded" } ] }

如需詳細資訊,請參閱 AWS CodePipeline 使用者指南 中的檢視執行歷史記錄

下列程式碼範例示範如何使用 list-pipelines

AWS CLI

檢視管道清單

此範例會列出與使用者帳戶相關聯的所有 AWS CodePipeline 管道 AWS 。

命令:

aws codepipeline list-pipelines

輸出:

{ "pipelines": [ { "updated": 1439504274.641, "version": 1, "name": "MyFirstPipeline", "created": 1439504274.641 }, { "updated": 1436461837.992, "version": 2, "name": "MySecondPipeline", "created": 1436460801.381 } ] }
  • 如需API詳細資訊,請參閱 命令參考 ListPipelines中的 。 AWS CLI

下列程式碼範例示範如何使用 list-tags-for-resource

AWS CLI

列出標籤

下列list-tags-for-resource範例會擷取連接至指定管道資源的所有標籤清單。

aws codepipeline list-tags-for-resource \ --resource-arn arn:aws:codepipeline:us-east-1:123456789012:MyPipeline

輸出:

{ "tags": { "Project": "ProjectA", "IscontainerBased": "true" } }

如需詳細資訊,請參閱 使用者指南 中的檢視管道 (CLI) 的標籤AWS CodePipeline

下列程式碼範例示範如何使用 list-webhooks

AWS CLI

列出 Webhook

下列list-webhooks範例會擷取連接至指定管道資源的所有標籤清單。

aws codepipeline list-webhooks \ --endpoint-url "https://codepipeline.eu-central-1.amazonaws.com" \ --region "eu-central-1"

輸出:

{ "webhooks": [ { "url": "https://webhooks.domain.com/trigger111111111EXAMPLE11111111111111111": { "authenticationConfiguration": { "SecretToken": "Secret" }, "name": "my-webhook", "authentication": "GITHUB_HMAC", "targetPipeline": "my-Pipeline", "targetAction": "Source", "filters": [ { "jsonPath": "$.ref", "matchEquals": "refs/heads/{Branch}" } ] }, "arn": "arn:aws:codepipeline:eu-central-1:123456789012:webhook:my-webhook" } ] }

如需詳細資訊,請參閱 AWS CodePipeline 使用者指南 中的列出您帳戶中的 Webhook

  • 如需API詳細資訊,請參閱 命令參考 ListWebhooks中的 。 AWS CLI

下列程式碼範例示範如何使用 poll-for-jobs

AWS CLI

檢視任何可用的任務

此範例會傳回任務工作者採取行動的任何任務的相關資訊。此範例使用預先定義的JSON檔案 (MyActionTypeInfo.json) 來提供有關作業工作者處理任務之動作類型的資訊。此命令僅用於自訂動作。呼叫此命令時, 會 AWS CodePipeline 傳回用於儲存管道成品之 Amazon S3 儲存貯體的臨時憑證。如果定義了任何秘密值,此命令也會傳回為動作定義的任何秘密值。

命令:

aws codepipeline poll-for-jobs --cli-input-json file://MyActionTypeInfo.json

JSON 檔案範例內容:

{ "actionTypeId": { "category": "Test", "owner": "Custom", "provider": "MyJenkinsProviderName", "version": "1" }, "maxBatchSize": 5, "queryParam": { "ProjectName": "MyJenkinsTestProject" } }

輸出:

{ "jobs": [ { "accountId": "111111111111", "data": { "actionConfiguration": { "__type": "ActionConfiguration", "configuration": { "ProjectName": "MyJenkinsExampleTestProject" } }, "actionTypeId": { "__type": "ActionTypeId", "category": "Test", "owner": "Custom", "provider": "MyJenkinsProviderName", "version": "1" }, "artifactCredentials": { "__type": "AWSSessionCredentials", "accessKeyId": "AKIAIOSFODNN7EXAMPLE", "secretAccessKey": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY", "sessionToken": "fICCQD6m7oRw0uXOjANBgkqhkiG9w0BAQUFADCBiDELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAldBMRAwDgYDVQQHEwdTZWF0dGxlMQ8wDQYDVQQKEwZBbWF6b24xFDASBgNVBAsTC0lBTSBDb25zb2xlMRIwEAYDVQQDEwlUZXN0Q2lsYWMxHzAdBgkqhkiG9w0BCQEWEG5vb25lQGFtYXpvbi5jb20wHhcNMTEwNDI1MjA0NTIxWhcNMTIwNDI0MjA0NTIxWjCBiDELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAldBMRAwDgYDVQQHEwdTZWF0dGxlMQ8wDQYDVQQKEwZBbWF6b24xFDASBgNVBAsTC0lBTSBDb25zb2xlMRIwEAYDVQQDEwlUZXN0Q2lsYWMxHzAdBgkqhkiG9w0BCQEWEG5vb25lQGFtYXpvbi5jb20wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAMaK0dn+a4GmWIWJ21uUSfwfEvySWtC2XADZ4nB+BLYgVIk60CpiwsZ3G93vUEIO3IyNoH/f0wYK8m9TrDHudUZg3qX4waLG5M43q7Wgc/MbQITxOUSQv7c7ugFFDzQGBzZswY6786m86gpEIbb3OhjZnzcvQAaRHhdlQWIMm2nrAgMBAAEwDQYJKoZIhvcNAQEFBQADgYEAtCu4nUhVVxYUntneD9+h8Mg9q6q+auNKyExzyLwaxlAoo7TJHidbtS4J5iNmZgXL0FkbFFBjvSfpJIlJ00zbhNYS5f6GuoEDmFJl0ZxBHjJnyp378OD8uTs7fLvjx79LjSTbNYiytVbZPQUQ5Yaxu2jXnimvw3rrszlaEXAMPLE=" }, "inputArtifacts": [ { "__type": "Artifact", "location": { "s3Location": { "bucketName": "codepipeline-us-east-1-11EXAMPLE11", "objectKey": "MySecondPipeline/MyAppBuild/EXAMPLE" }, "type": "S3" }, "name": "MyAppBuild" } ], "outputArtifacts": [], "pipelineContext": { "__type": "PipelineContext", "action": { "name": "MyJenkinsTest-Action" }, "pipelineName": "MySecondPipeline", "stage": { "name": "Testing" } } }, "id": "ef66c259-64f9-EXAMPLE", "nonce": "3" } ] }
  • 如需API詳細資訊,請參閱 命令參考 PollForJobs中的 。 AWS CLI

下列程式碼範例示範如何使用 put-webhook

AWS CLI

建立 Webhook

下列put-webhook範例會為第 1 GitHub 版來源動作建立 Webhook。建立 Webhook 之後,您必須使用 register-webhook-with-third-party 命令進行註冊。

aws codepipeline put-webhook \ --cli-input-json file://webhook_json.json \ --region "eu-central-1"

webhook_json.json 的內容:

{ "webhook": { "name": "my-webhook", "targetPipeline": "pipeline_name", "targetAction": "source_action_name", "filters": [ { "jsonPath": "$.ref", "matchEquals": "refs/heads/{Branch}" } ], "authentication": "GITHUB_HMAC", "authenticationConfiguration": { "SecretToken": "secret" } } }

輸出:

{ "webhook": { "url": "https://webhooks.domain.com/trigger111111111EXAMPLE11111111111111111", "definition": { "authenticationConfiguration": { "SecretToken": "secret" }, "name": "my-webhook", "authentication": "GITHUB_HMAC", "targetPipeline": "pipeline_name", "targetAction": "Source", "filters": [ { "jsonPath": "$.ref", "matchEquals": "refs/heads/{Branch}" } ] }, "arn": "arn:aws:codepipeline:eu-central-1:123456789012:webhook:my-webhook" }, "tags": [ { "key": "Project", "value": "ProjectA" } ] }

如需詳細資訊,請參閱 AWS CodePipeline 使用者指南 中的為 GitHub 來源建立 Webhook

  • 如需API詳細資訊,請參閱 命令參考 PutWebhook中的 。 AWS CLI

下列程式碼範例示範如何使用 retry-stage-execution

AWS CLI

若要重試失敗的動作

下列retry-stage-execution範例會重試具有失敗動作的階段。

aws codepipeline retry-stage-execution \ --pipeline-name MyPipeline \ --stage-name Deploy \ --pipeline-execution-id b59babff-5f34-EXAMPLE \ --retry-mode FAILED_ACTIONS

輸出:

{ "pipelineExecutionId": "b59babff-5f34-EXAMPLE" }

如需詳細資訊,請參閱 AWS CodePipeline 使用者指南 中的重試失敗動作 (CLI)

下列程式碼範例示範如何使用 start-pipeline-execution

AWS CLI

透過管道執行最新版本

此範例會透過名為 "MyFirstPipeline" 的管道,執行管道來源階段中存在的最新修訂。

命令:

aws codepipeline start-pipeline-execution --name MyFirstPipeline

輸出:

{ "pipelineExecutionId": "3137f7cb-7cf7-EXAMPLE" }

下列程式碼範例示範如何使用 stop-pipeline-execution

AWS CLI

停止管道執行

下列stop-pipeline-execution範例預設為等待進行中的動作完成,然後停止管道。如果執行已處於 Stopping (停止中) 狀態,您就無法選擇停止並等待。您可以選擇停止並捨棄已處於 Stopping (停止中) 狀態的執行。

aws codepipeline stop-pipeline-execution \ --pipeline-name MyFirstPipeline \ --pipeline-execution-id d-EXAMPLE \ --reason "Stopping pipeline after the build action is done"

此命令不會傳回輸出。

如需詳細資訊,請參閱 AWS CodePipeline 使用者指南 中的停止管道執行 (CLI)

下列程式碼範例示範如何使用 tag-resource

AWS CLI

標記資源

下列tag-resource範例會將一組提供的標籤與管道建立關聯。使用此命令來新增或編輯標籤。

aws codepipeline tag-resource \ --resource-arn arn:aws:codepipeline:us-east-1:123456789012:MyPipeline \ --tags key=Project,value=ProjectA key=IscontainerBased,value=true

此命令不會產生輸出。

如需詳細資訊,請參閱 AWS CodePipeline 使用者指南 中的將標籤新增至管道 (CLI)

  • 如需API詳細資訊,請參閱 命令參考 TagResource中的 。 AWS CLI

下列程式碼範例示範如何使用 untag-resource

AWS CLI

從連線資源移除 AWS 標籤

下列untag-resource範例會從指定的資源移除標籤。

aws codepipeline untag-resource \ --resource-arn arn:aws:codepipeline:us-east-1:123456789012:MyPipeline \ --tag-keys Project IscontainerBased

此命令不會產生輸出。

如需詳細資訊,請參閱 AWS CodePipeline 使用者指南 中的從管道 (CLI) 移除標籤

  • 如需API詳細資訊,請參閱 命令參考 UntagResource中的 。 AWS CLI

下列程式碼範例示範如何使用 update-pipeline

AWS CLI

更新管道的結構

此範例使用 update-pipeline 命令搭配 --cli-input-json argument。此範例使用預先定義的JSON檔案 (MyFirstPipeline.json) 來更新管道的結構。 AWS CodePipeline 會識別JSON檔案中包含的管道名稱,然後套用管道結構中修改欄位的任何變更來更新管道。

建立預先定義的JSON檔案時,請使用下列準則:

如果您使用的是使用 get-pipeline 命令擷取的管道結構,則必須從JSON檔案中的管道結構中移除中繼資料區段 (檔案中的「中繼資料」:{ } 行和「建立的」、「管道 ARN,」和「更新」欄位)。無法變更管道名稱。

命令:

aws codepipeline update-pipeline --cli-input-json file://MyFirstPipeline.json

範例JSON檔案內容:

{ "pipeline": { "roleArn": "arn:aws:iam::111111111111:role/AWS-CodePipeline-Service", "stages": [ { "name": "Source", "actions": [ { "inputArtifacts": [], "name": "Source", "actionTypeId": { "category": "Source", "owner": "AWS", "version": "1", "provider": "S3" }, "outputArtifacts": [ { "name": "MyApp" } ], "configuration": { "S3Bucket": "awscodepipeline-demo-bucket2", "S3ObjectKey": "aws-codepipeline-s3-aws-codedeploy_linux.zip" }, "runOrder": 1 } ] }, { "name": "Beta", "actions": [ { "inputArtifacts": [ { "name": "MyApp" } ], "name": "CodePipelineDemoFleet", "actionTypeId": { "category": "Deploy", "owner": "AWS", "version": "1", "provider": "CodeDeploy" }, "outputArtifacts": [], "configuration": { "ApplicationName": "CodePipelineDemoApplication", "DeploymentGroupName": "CodePipelineDemoFleet" }, "runOrder": 1 } ] } ], "artifactStore": { "type": "S3", "location": "codepipeline-us-east-1-11EXAMPLE11" }, "name": "MyFirstPipeline", "version": 1 } }

輸出:

{ "pipeline": { "artifactStore": { "location": "codepipeline-us-east-1-11EXAMPLE11", "type": "S3" }, "name": "MyFirstPipeline", "roleArn": "arn:aws:iam::111111111111:role/AWS-CodePipeline-Service", "stages": [ { "actions": [ { "actionTypeId": { "__type": "ActionTypeId", "category": "Source", "owner": "AWS", "provider": "S3", "version": "1" }, "configuration": { "S3Bucket": "awscodepipeline-demo-bucket2", "S3ObjectKey": "aws-codepipeline-s3-aws-codedeploy_linux.zip" }, "inputArtifacts": [], "name": "Source", "outputArtifacts": [ { "name": "MyApp" } ], "runOrder": 1 } ], "name": "Source" }, { "actions": [ { "actionTypeId": { "__type": "ActionTypeId", "category": "Deploy", "owner": "AWS", "provider": "CodeDeploy", "version": "1" }, "configuration": { "ApplicationName": "CodePipelineDemoApplication", "DeploymentGroupName": "CodePipelineDemoFleet" }, "inputArtifacts": [ { "name": "MyApp" } ], "name": "CodePipelineDemoFleet", "outputArtifacts": [], "runOrder": 1 } ], "name": "Beta" } ], "version": 3 } }
  • 如需API詳細資訊,請參閱 命令參考 UpdatePipeline中的 。 AWS CLI