首页 > 解决方案 > 使用第三方 GitHub 源提供程序为 AWS Pipeline 保留 git 操作

问题描述

我有一个配置为使用 ThridParty GitHub 源提供程序的管道,如下所示:

...
Resources:
  DevPipeline:
    Type: AWS::CodePipeline::Pipeline
    Properties:
      Name: my-pipeline
      RoleArn: !Ref 'PipelineRole'
      Stages:
        - Name: Source
          Actions:
            - Name: GitHub
              ActionTypeId:
                Category: Source
                Owner: ThirdParty
                Version: 1
                Provider: GitHub
              Configuration:
                Owner: !Ref GitHubOwner
                Repo: !Ref GitHubRepo
                Branch: !Ref GitHubBranch
                OAuthToken: !Ref GitHubToken
              OutputArtifacts:
                - Name: JavaSource
              RunOrder: 1
...

我希望能够git在以下构建步骤中对源代码运行操作。但是,此源操作不包括.git输出工件中的文件夹。

如何修改它以便我可以访问gitrepo 上的操作?

标签: githubamazon-cloudformationaws-codepipeline

解决方案


CodePipeline 最近发布了新版本的 GitHub Source 操作,该操作执行 git 存储库的实际克隆,而不是从 GitHub 获取“zip”包。

新的 GitHub 操作(版本 2)使用 CodeStarSourceConnection。因此,我们只需要在管道的源阶段指定 CodeStarSourceConnection [1] 源操作提供程序。CloudFormation 还支持 AWS::CodeStarConnections::Connection 资源 [2]。您可以引用现有 Connection 的 ARN,或在 CloudFormation 中创建一个新的。现有连接可在此处找到 [0]。

这是一个示例模板片段:

Resources:
  CodeStarConnection:
    Type: 'AWS::CodeStarConnections::Connection'
    Properties:
      ConnectionName: MyGitHubConnection
      ProviderType: GitHub
  CodePipeline:
    Type: 'AWS::CodePipeline::Pipeline'
    Properties:
      Stages:
        - Name: Source
          Actions:
            - Name: SourceAction
              ActionTypeId:
                Category: Source
                Owner: AWS
                Version: 1
                Provider: CodeStarSourceConnection
              OutputArtifacts:
                - Name: SourceArtifact
              Configuration:
                ConnectionArn: !Ref CodeStarConnection
                BranchName: master
                FullRepositoryId: username/repository
              RunOrder: 1
      ... ...

注意:通过 CloudFormation 创建的连接默认处于 PENDING 状态。您可以通过更新控制台 [3] 中的连接来使其状态为 AVAILABLE。连接可用后,您可以将 CodePipeline 与 Github 版本 2 源操作一起使用。

参考:

[0] 连接 - https://console.aws.amazon.com/codesuite/settings/connections

[1] CodeStarSourceConnection - https://docs.aws.amazon.com/codepipeline/latest/userguide/action-reference-CodestarConnectionSource.html

[2] AWS::CodeStarConnections::Connection - https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-codestarconnections-connection.html

[3] 更新挂起的连接 - https://docs.aws.amazon.com/dtconsole/latest/userguide/connections-update.html


推荐阅读