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

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

CodePipeline 使用範例 AWS CLI

下列程式碼範例說明如何使用 AWS Command Line Interface 與來執行動作及實作常見案例 CodePipeline。

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

Scenarios (案例) 是向您展示如何呼叫相同服務中的多個函數來完成特定任務的程式碼範例。

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

主題

動作

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

AWS CLI

若要擷取指定工作的相關資訊

此範例會傳回指定工作的相關資訊,包括該工作的狀態 (如果存在)。這僅適用於工作人員和自訂動作。要確定隨機數和任務 ID 的值,請使用 aws 代碼 poll-for-jobs管道。

命令:

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

輸出:

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

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

AWS CLI

建立自訂動作

此範例會建立自訂動作,以 AWS CodePipeline 使用包含自訂動作結構的已建立 MyCustomAction JSON 檔案 (此處名為 .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 詳細資訊,請參閱AWS CLI 命令參考CreatePipeline中的。

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

AWS CLI

若要刪除自訂動作

此範例會使用已建立的 JSON 檔案 (名為 DeleteMyCustomAction .json) 刪除中 AWS CodePipeline 的自訂動作,該 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。使用列表管線指令來檢視與您 AWS 的帳戶相關聯的管道清單。

命令:

aws codepipeline delete-pipeline --name MySecondPipeline

輸出:

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

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

AWS CLI

若要刪除網路掛接

下列delete-webhook範例會刪除 GitHub 版本 1 來源動作的 Webhook。您必須先使用指deregister-webhook-with-third-party令來取消註冊 Webhook,然後才能刪除它。

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

此命令不會產生輸出。

如需詳細資訊,請參閱《AWS CodePipeline 使用指南》的「刪除 GitHub 來源的 Webhook」。

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

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

AWS CLI

若要取消註冊網路掛接

下列deregister-webhook-with-third-party範例會刪除 GitHub 版本 1 來源動作的 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

若要取得工作的詳細資訊

此範例會傳回其識別碼以 F4F4FF82-2D11-範例表示之工作的相關詳細資訊。此指令僅用於自訂動作。呼叫此命令時,如果自訂動作需要,會 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 詳細資訊,請參閱AWS CLI 命令參考GetJobDetails中的。

下列程式碼範例會示範如何使用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 詳細資訊,請參閱AWS CLI 命令參考GetPipelineState中的。

下列程式碼範例會示範如何使用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 詳細資訊,請參閱AWS CLI 命令參考GetPipeline中的。

下列程式碼範例會示範如何使用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 選項僅傳回自訂動作。

命令:

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 詳細資訊,請參閱AWS CLI 命令參考ListActionTypes中的。

下列程式碼範例會示範如何使用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 帳戶相關聯的所有 AWS CodePipeline 管線。

命令:

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 詳細資訊,請參閱AWS CLI 命令參考ListPipelines中的。

下列程式碼範例會示範如何使用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" } }

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

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

AWS CLI

列出網路掛接

下列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 詳細資訊,請參閱AWS CLI 命令參考ListWebhooks中的。

下列程式碼範例會示範如何使用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 詳細資訊,請參閱AWS CLI 命令參考PollForJobs中的。

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

AWS CLI

若要建立網路掛接

下列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 詳細資訊,請參閱AWS CLI 命令參考PutWebhook中的。

下列程式碼範例會示範如何使用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 詳細資訊,請參閱AWS CLI 命令參考TagResource中的。

下列程式碼範例會示範如何使用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 詳細資訊,請參閱AWS CLI 命令參考UntagResource中的。

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

AWS CLI

更新配管結構

此範例使用具有-引數的更新管道命令。cli-input-json 此範例使用預先定義的 JSON 檔案 (MyFirstPipeline.json) 來更新管線的結構。 AWS CodePipeline 識別 JSON 檔案中包含的管線名稱,然後套用管線結構中已修改欄位的任何變更,以更新管線。

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

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

命令:

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 詳細資訊,請參閱AWS CLI 命令參考UpdatePipeline中的。