AWS 代码承诺构建库
AWS CDK v1在2023-06-01上达到了支持结束. 此软件包不再更新,用户应该迁移到 AWS CDK v2.
关于如何移徙的更多信息,请参见: 移动到 AWS CDK v2 指南。 。 。 .
AWS CodeCommit是一种版本控制服务,可以让您在AWS云中私下存储和管理Git寄存器.
关于《守则承诺》的进一步信息, 见 AWS 代码承诺文档。 。 。 .
要在您的堆栈中添加 CodeCommit 仓库 :
const repo = new codecommit.Repository(this, 'Repository', {
repositoryName: 'MyRepositoryName',
description: 'Some description.', // optional property
});
使用 repositoryCloneUrlHttp, (中文(简体) ), repositoryCloneUrlSsh 或者说 repositoryCloneUrlGrc
属性以克隆您的仓库.
要在您的仓库中添加 Amazon SNS 触发器 :
declare const repo: codecommit.Repository;
// trigger is established for all repository actions on all branches by default.
repo.notify('arn:aws:sns:*:123456789012:my_topic');
增加初始承诺
可以通过 Code 课.
它提供了从目录中加载代码的方法, .zip 文件并来自预创建的 CDK 资产.
示例
const repo = new codecommit.Repository(this, 'Repository', {
repositoryName: 'MyRepositoryName',
code: codecommit.Code.fromDirectory(path.join(__dirname, 'directory/'), 'develop'), // optional property, branch parameter can be omitted
});
活动
代码承诺寄存器释放出亚马逊云观察事件,用于某些活动.
使用 repo.onXxx 确定触发这些事件的规则的方法
并因此援引目标:
import * as sns from '@aws-cdk/aws-sns';
import * as targets from '@aws-cdk/aws-events-targets';
declare const repo: codecommit.Repository;
declare const project: codebuild.PipelineProject;
declare const myTopic: sns.Topic;
// starts a CodeBuild project when a commit is pushed to the "master" branch of the repo
repo.onCommit('CommitToMaster', {
target: new targets.CodeBuildProject(project),
branches: ['master'],
});
// publishes a message to an Amazon SNS topic when a comment is made on a pull request
const rule = repo.onCommentOnPullRequest('CommentOnPullRequest', {
target: new targets.SnsTopic(myTopic),
});
代码星通知
要定义寄存器的代码星通知规则,请使用其中之一 notifyOnXxx() 方法。 。 .
它们与 onXxx() 云表事件的方法:
import * as chatbot from '@aws-cdk/aws-chatbot';
declare const repository: codecommit.Repository;
const target = new chatbot.SlackChannelConfiguration(this, 'MySlackChannel', {
slackChannelConfigurationName: 'YOUR_CHANNEL_NAME',
slackWorkspaceId: 'YOUR_SLACK_WORKSPACE_ID',
slackChannelId: 'YOUR_SLACK_CHANNEL_ID',
});
const rule = repository.notifyOnPullRequestCreated('NotifyOnPullRequestCreated', target);