CodePipeline contoh menggunakan AWS CLI - AWS Command Line Interface

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

CodePipeline contoh menggunakan AWS CLI

Contoh kode berikut menunjukkan cara melakukan tindakan dan mengimplementasikan skenario umum dengan menggunakan AWS Command Line Interface with CodePipeline.

Tindakan adalah kutipan kode dari program yang lebih besar dan harus dijalankan dalam konteks. Sementara tindakan menunjukkan cara memanggil fungsi layanan individual, Anda dapat melihat tindakan dalam konteks dalam skenario terkait.

Setiap contoh menyertakan tautan ke kode sumber lengkap, di mana Anda dapat menemukan instruksi tentang cara mengatur dan menjalankan kode dalam konteks.

Tindakan

Contoh kode berikut menunjukkan cara menggunakanacknowledge-job.

AWS CLI

Untuk mengambil informasi tentang pekerjaan tertentu

Contoh ini mengembalikan informasi tentang pekerjaan tertentu, termasuk status pekerjaan itu jika ada. Ini hanya digunakan untuk pekerja kerja dan tindakan khusus. Untuk menentukan nilai nonce dan ID pekerjaan, gunakan aws poll-for-jobs codepipeline.

Perintah:

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

Output:

{ "status": "InProgress" }
  • Untuk API detailnya, lihat AcknowledgeJobdi Referensi AWS CLI Perintah.

Contoh kode berikut menunjukkan cara menggunakancreate-custom-action-type.

AWS CLI

Untuk membuat tindakan kustom

Contoh ini membuat tindakan kustom untuk AWS CodePipeline menggunakan JSON file yang sudah dibuat (di sini bernama MyCustomAction .json) yang berisi struktur tindakan kustom. Untuk informasi selengkapnya tentang persyaratan untuk membuat tindakan kustom, termasuk struktur file, lihat Panduan AWS CodePipeline Pengguna.

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

Isi JSON fileMyCustomAction.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 } }

Perintah ini mengembalikan struktur tindakan kustom.

Contoh kode berikut menunjukkan cara menggunakancreate-pipeline.

AWS CLI

Untuk membuat pipa

Contoh ini membuat pipeline dalam AWS CodePipeline menggunakan JSON file yang sudah dibuat (di sini bernama MySecondPipeline .json) yang berisi struktur pipeline. Untuk informasi selengkapnya tentang persyaratan untuk membuat pipeline, termasuk struktur file, lihat Panduan AWS CodePipeline Pengguna.

Perintah:

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

JSONisi sampel file:

{ "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 } }

Output:

This command returns the structure of the pipeline.
  • Untuk API detailnya, lihat CreatePipelinedi Referensi AWS CLI Perintah.

Contoh kode berikut menunjukkan cara menggunakandelete-custom-action-type.

AWS CLI

Untuk menghapus tindakan kustom

Contoh ini menghapus tindakan kustom AWS CodePipeline dengan menggunakan JSON file yang sudah dibuat (di sini bernama DeleteMyCustomAction .json) yang berisi tipe tindakan, nama penyedia, dan nomor versi tindakan yang akan dihapus. Gunakan list-action-types perintah untuk melihat nilai yang benar untuk kategori, versi, dan penyedia.

Perintah:

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

JSONisi sampel file:

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

Output:

None.

Contoh kode berikut menunjukkan cara menggunakandelete-pipeline.

AWS CLI

Untuk menghapus pipa

Contoh ini menghapus pipeline bernama MySecondPipeline from AWS CodePipeline. Gunakan perintah list-pipelines untuk melihat daftar pipeline yang terkait dengan akun Anda. AWS

Perintah:

aws codepipeline delete-pipeline --name MySecondPipeline

Output:

None.
  • Untuk API detailnya, lihat DeletePipelinedi Referensi AWS CLI Perintah.

Contoh kode berikut menunjukkan cara menggunakandelete-webhook.

AWS CLI

Untuk menghapus webhook

delete-webhookContoh berikut menghapus webhook untuk tindakan sumber GitHub versi 1. Anda harus menggunakan deregister-webhook-with-third-party perintah untuk membatalkan pendaftaran webhook sebelum Anda menghapusnya.

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

Perintah ini tidak menghasilkan output.

Untuk informasi selengkapnya, lihat Menghapus webhook untuk GitHub sumber Anda di Panduan AWS CodePipeline Pengguna.

  • Untuk API detailnya, lihat DeleteWebhookdi Referensi AWS CLI Perintah.

Contoh kode berikut menunjukkan cara menggunakanderegister-webhook-with-third-party.

AWS CLI

Untuk membatalkan pendaftaran webhook

deregister-webhook-with-third-partyContoh berikut menghapus webhook untuk tindakan sumber GitHub versi 1. Anda harus membatalkan pendaftaran webhook sebelum menghapusnya.

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

Perintah ini tidak menghasilkan output.

Untuk informasi selengkapnya, lihat Menghapus webhook untuk GitHub sumber Anda di Panduan AWS CodePipeline Pengguna.

Contoh kode berikut menunjukkan cara menggunakandisable-stage-transition.

AWS CLI

Untuk menonaktifkan transisi ke tahap dalam pipa

Contoh ini menonaktifkan transisi ke tahap Beta dari MyFirstPipeline pipeline di. AWS CodePipeline

Perintah:

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

Output:

None.

Contoh kode berikut menunjukkan cara menggunakanenable-stage-transition.

AWS CLI

Untuk mengaktifkan transisi ke tahap dalam pipa

Contoh ini memungkinkan transisi ke tahap Beta dari MyFirstPipeline pipeline di AWS CodePipeline.

Perintah:

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

Output:

None.

Contoh kode berikut menunjukkan cara menggunakanget-job-details.

AWS CLI

Untuk mendapatkan detail pekerjaan

Contoh ini mengembalikan rincian tentang pekerjaan yang ID diwakili oleh f4f4ff82-2d11-. EXAMPLE Perintah ini hanya digunakan untuk tindakan kustom. Saat perintah ini dipanggil, AWS CodePipeline mengembalikan kredensi sementara untuk bucket Amazon S3 yang digunakan untuk menyimpan artefak untuk pipeline, jika diperlukan untuk tindakan kustom. Perintah ini juga akan mengembalikan nilai rahasia yang ditentukan untuk tindakan, jika ada yang ditentukan.

Perintah:

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

Output:

{ "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" } }
  • Untuk API detailnya, lihat GetJobDetailsdi Referensi AWS CLI Perintah.

Contoh kode berikut menunjukkan cara menggunakanget-pipeline-state.

AWS CLI

Untuk mendapatkan informasi tentang keadaan pipa

Contoh ini mengembalikan status terbaru dari pipeline bernama MyFirstPipeline.

Perintah:

aws codepipeline get-pipeline-state --name MyFirstPipeline

Output:

{ "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 }

Contoh kode berikut menunjukkan cara menggunakanget-pipeline.

AWS CLI

Untuk melihat struktur pipa

Contoh ini mengembalikan struktur pipa bernama MyFirstPipeline.

Perintah:

aws codepipeline get-pipeline --name MyFirstPipeline

Output:

{ "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 } }
  • Untuk API detailnya, lihat GetPipelinedi Referensi AWS CLI Perintah.

Contoh kode berikut menunjukkan cara menggunakanlist-action-executions.

AWS CLI

Untuk membuat daftar eksekusi tindakan

list-action-executionsContoh berikut menampilkan detail eksekusi tindakan untuk pipeline, seperti ID eksekusi tindakan, artefak input, artefak keluaran, hasil eksekusi, dan status.

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

Output:

{ "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" } } }, . . . .

Untuk informasi selengkapnya, lihat Lihat eksekusi tindakan (CLI) di Panduan AWS CodePipeline Pengguna.

Contoh kode berikut menunjukkan cara menggunakanlist-action-types.

AWS CLI

Untuk melihat jenis tindakan yang tersedia

Digunakan dengan sendirinya, list-action-types perintah mengembalikan struktur semua tindakan yang tersedia untuk AWS akun Anda. Contoh ini menggunakan action-owner-filter opsi -- untuk mengembalikan hanya tindakan khusus.

Perintah:

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

Output:

{ "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}" } } ] }

Contoh kode berikut menunjukkan cara menggunakanlist-pipeline-executions.

AWS CLI

Untuk melihat riwayat eksekusi pipeline

list-pipeline-executionsContoh berikut menunjukkan riwayat eksekusi pipeline untuk pipeline di AWS akun Anda.

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

Output:

{ "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" } ] }

Untuk informasi selengkapnya, lihat Melihat riwayat eksekusi di Panduan AWS CodePipeline Pengguna.

Contoh kode berikut menunjukkan cara menggunakanlist-pipelines.

AWS CLI

Untuk melihat daftar saluran pipa

Contoh ini mencantumkan semua AWS CodePipeline pipeline yang terkait dengan AWS akun pengguna.

Perintah:

aws codepipeline list-pipelines

Output:

{ "pipelines": [ { "updated": 1439504274.641, "version": 1, "name": "MyFirstPipeline", "created": 1439504274.641 }, { "updated": 1436461837.992, "version": 2, "name": "MySecondPipeline", "created": 1436460801.381 } ] }
  • Untuk API detailnya, lihat ListPipelinesdi Referensi AWS CLI Perintah.

Contoh kode berikut menunjukkan cara menggunakanlist-tags-for-resource.

AWS CLI

Untuk daftar tag

list-tags-for-resourceContoh berikut mengambil daftar semua tag yang dilampirkan ke sumber pipa yang ditentukan.

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

Output:

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

Untuk informasi selengkapnya, lihat Melihat tag untuk pipeline (CLI) di Panduan AWS CodePipeline Pengguna.

Contoh kode berikut menunjukkan cara menggunakanlist-webhooks.

AWS CLI

Untuk daftar webhooks

list-webhooksContoh berikut mengambil daftar semua tag yang dilampirkan ke sumber pipa yang ditentukan.

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

Output:

{ "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" } ] }

Untuk informasi selengkapnya, lihat Daftar webhook di akun Anda di AWS CodePipeline Panduan Pengguna.

  • Untuk API detailnya, lihat ListWebhooksdi Referensi AWS CLI Perintah.

Contoh kode berikut menunjukkan cara menggunakanpoll-for-jobs.

AWS CLI

Untuk melihat pekerjaan yang tersedia

Contoh ini mengembalikan informasi tentang pekerjaan apa pun untuk ditindaklanjuti oleh pekerja kerja. Contoh ini menggunakan JSON file yang telah ditentukan sebelumnya (MyActionTypeInfo.json) untuk memberikan informasi tentang jenis tindakan yang pekerja pekerjaan memproses pekerjaan. Perintah ini hanya digunakan untuk tindakan kustom. Saat perintah ini dipanggil, AWS CodePipeline mengembalikan kredensi sementara untuk bucket Amazon S3 yang digunakan untuk menyimpan artefak untuk pipeline. Perintah ini juga akan mengembalikan nilai rahasia yang ditentukan untuk tindakan, jika ada yang ditentukan.

Perintah:

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

JSONisi sampel file:

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

Output:

{ "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" } ] }
  • Untuk API detailnya, lihat PollForJobsdi Referensi AWS CLI Perintah.

Contoh kode berikut menunjukkan cara menggunakanput-webhook.

AWS CLI

Untuk membuat webhook

put-webhookContoh berikut membuat webhook untuk aksi sumber GitHub versi 1. Setelah Anda membuat webhook, Anda harus menggunakan perintah register-webhook-with-third -party untuk mendaftarkannya.

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

Isi dari 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" } } }

Output:

{ "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" } ] }

Untuk informasi selengkapnya, lihat Membuat webhook untuk GitHub sumber di Panduan AWS CodePipeline Pengguna.

  • Untuk API detailnya, lihat PutWebhookdi Referensi AWS CLI Perintah.

Contoh kode berikut menunjukkan cara menggunakanretry-stage-execution.

AWS CLI

Untuk mencoba lagi tindakan yang gagal

retry-stage-executionContoh berikut mencoba ulang tahap yang memiliki tindakan gagal.

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

Output:

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

Untuk informasi selengkapnya, lihat Coba lagi tindakan yang gagal (CLI) di Panduan AWS CodePipeline Pengguna.

Contoh kode berikut menunjukkan cara menggunakanstart-pipeline-execution.

AWS CLI

Untuk menjalankan revisi terbaru melalui pipeline

Contoh ini menjalankan revisi terbaru yang ada di tahap sumber pipa melalui pipa bernama "MyFirstPipeline”.

Perintah:

aws codepipeline start-pipeline-execution --name MyFirstPipeline

Output:

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

Contoh kode berikut menunjukkan cara menggunakanstop-pipeline-execution.

AWS CLI

Untuk menghentikan eksekusi pipeline

stop-pipeline-executionContoh berikut secara default menunggu hingga tindakan yang sedang berlangsung selesai, dan kemudian menghentikan pipeline. Anda tidak dapat memilih untuk berhenti dan menunggu jika eksekusi sudah dalam status Berhenti. Anda dapat memilih untuk berhenti dan meninggalkan eksekusi yang sudah dalam status Berhenti.

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

Perintah ini tidak mengembalikan output.

Untuk informasi selengkapnya, lihat Menghentikan eksekusi pipeline (CLI) di Panduan AWS CodePipeline Pengguna.

Contoh kode berikut menunjukkan cara menggunakantag-resource.

AWS CLI

Untuk menandai sumber daya

tag-resourceContoh berikut mengaitkan satu set tag yang disediakan dengan pipeline. Gunakan perintah ini untuk menambah atau mengedit tag.

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

Perintah ini tidak menghasilkan output.

Untuk informasi selengkapnya, lihat Menambahkan tag ke pipeline (CLI) di Panduan AWS CodePipeline Pengguna.

  • Untuk API detailnya, lihat TagResourcedi Referensi AWS CLI Perintah.

Contoh kode berikut menunjukkan cara menggunakanuntag-resource.

AWS CLI

Untuk menghapus AWS tag dari sumber daya koneksi

untag-resourceContoh berikut menghapus tag dari sumber daya yang ditentukan.

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

Perintah ini tidak menghasilkan output.

Untuk informasi selengkapnya, lihat Menghapus tag dari pipeline (CLI) di Panduan AWS CodePipeline Pengguna.

  • Untuk API detailnya, lihat UntagResourcedi Referensi AWS CLI Perintah.

Contoh kode berikut menunjukkan cara menggunakanupdate-pipeline.

AWS CLI

Untuk memperbarui struktur pipa

Contoh ini menggunakan perintah update-pipeline dengan argumen --. cli-input-json Contoh ini menggunakan JSON file yang telah ditentukan sebelumnya (MyFirstPipeline.json) untuk memperbarui struktur pipeline. AWS CodePipeline mengenali nama pipeline yang terkandung dalam JSON file, dan kemudian menerapkan perubahan apa pun dari bidang yang dimodifikasi dalam struktur pipa untuk memperbarui pipeline.

Gunakan panduan berikut saat membuat JSON file yang telah ditentukan sebelumnya:

Jika Anda bekerja dengan struktur pipa yang diambil menggunakan perintah get-pipeline, Anda harus menghapus bagian metadata dari struktur pipa dalam JSON file (baris “metadata”: {} dan bidang “dibuat,” “pipa,” dan “diperbarui” di dalamnya) .Nama pipa ARN tidak dapat diubah.

Perintah:

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

Isi JSON file sampel:

{ "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 } }

Output:

{ "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 } }
  • Untuk API detailnya, lihat UpdatePipelinedi Referensi AWS CLI Perintah.