简体   繁体   English

通过 AWS 上的 CDK 管道构建代码时,我可以在 Github 上标记我的代码吗?

[英]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.

相关问题 如何断开我的 Github 账户与 AWS Code Pipeline 的连接? - How can I disconnect my Github account from AWS Code Pipeline? Cloud Assembly Schema 版本不匹配——在 CDK 中构建代码管道 - Cloud Assembly Schema Version Mismatch - Building A Code Pipeline In The CDK 使用 CodeBuildStep 的代码管道的 AWS CDK 合成器错误 - AWS CDK synth errors out for a Code Pipeline with CodeBuildStep AWS CDK 代码管道开发 - Typescript 错误 TS2307 - AWS CDK Code Pipeline Development - Typescript Error TS2307 AWS CDK 代码管道开发 - 错误 TS1005:预期为“]” - AWS CDK Code Pipeline Development - error TS1005: ']' expected AWS CDK 代码管道开发——NodejsFunction Package.json 依赖项如何安装? - AWS CDK Code Pipeline Development - How Do I Install NodejsFunction Package.json Dependencies? 使用 AWS copilot 创建了一个管道,原始推送有效但是当我更改代码并将它们推送到 github 时它们没有显示 - Created a pipeline using AWS copilot, original push worked but when I make changes to code and push them to github they don't show up 如何创建代码管道阶段以在 github 中部署带有源代码的 React 应用程序? [CDK 2.0] - How to create a code pipeline stage to deploy React application with source code in github? [CDK 2.0] 在我的部署管道中使用 aws ecs run-task 命令时,我可以添加等待吗 - Can I add a wait when using aws ecs run-task command in my deployment pipeline 在 CDK ShellStep(管道)步骤中使用 AWS CLI - Use the AWS CLI in a CDK ShellStep (pipeline) step
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM