[英]Can I tag my code on Github when building it through a CDK Pipeline on AWS?
I have some GitHub repositories with my project source codes and I build them through CDK Pipelines on AWS.我有一些 GitHub 存储库和我的项目源代码,我通过 AWS 上的 CDK 管道构建它们。 I basically grab the source code, build the docker images and push them to the ECR.我基本上是获取源代码,构建 docker 图像并将它们推送到 ECR。 I was wondering if I could tag the versions on the code on GitHub through any step or code on the Pipeline, so I can keep track of the builds on the code.我想知道我是否可以通过管道上的任何步骤或代码在 GitHub 上的代码上标记版本,这样我就可以跟踪代码上的构建。 I tried looking it up but didn't find anything so I thought maybe I would have more luck here if anyone has done that.我尝试查找它但没有找到任何东西所以我想如果有人这样做的话我可能会在这里有更多的运气。
Here a working example of a pipeline initialization with CDKv2
using a CodeCommit
repo:这是一个使用CodeCommit
存储库使用CDKv2
进行管道初始化的工作示例:
import { Stack, StackProps, Stage, StageProps } from 'aws-cdk-lib';
import { Repository } from 'aws-cdk-lib/aws-codecommit';
import { PolicyStatement } from 'aws-cdk-lib/aws-iam';
import { CodeBuildStep, CodePipeline, CodePipelineSource, ManualApprovalStep } from 'aws-cdk-lib/pipelines';
import { Construct } from 'constructs';
// This will be your infrastructure code
import { InfrastructureStack } from './infrastructure-stack';
export interface PipelineStackProps extends StackProps {
readonly repository: string;
}
export class PipelineStack extends Stack {
constructor(scope: Construct, id: string, props: PipelineStackProps) {
super(scope, id, props);
const pipeline = new CodePipeline(this, 'pipelineID', {
pipelineName: "pipeline-name",
synth: new CodeBuildStep('Synth', {
input: CodePipelineSource.codeCommit(Repository.fromRepositoryArn(this, `repository`, props.repository), 'master'),
commands: [
'npm ci',
'npm run build',
'npx cdk synth',
],
rolePolicyStatements: [
new PolicyStatement({
actions: ['ssm:GetParameter'],
resources: [`*`],
})
]
}),
dockerEnabledForSynth: true
});
pipeline.addStage(new InfrastructureStage(this, 'qa'));
pipeline.addStage(new InfrastructureStage(this, 'prod'), {
pre: [new ManualApprovalStep('PromoteToProd')]
});
}
}
class InfrastructureStage extends Stage {
constructor(scope: Construct, id: string, props?: StageProps) {
super(scope, id, props);
new InfrastructureStack(this, "InfrastructureStack", {
environment: id
})
}
}
If you have a look at the following link you can view that CodePipelineSource
can interact with Github
using GitHubSourceOptions options and gitHub method.如果您查看以下链接,您可以看到CodePipelineSource
可以使用GitHubSourceOptions选项和gitHub方法与Github
交互。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.