使用第三方 GitHub 源提供商为 AWS Pipeline 保留 git 操作

Retain git operations for AWS Pipeline using ThirdParty GitHub source provider

我将管道配置为使用 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 文件夹。

如何修改它以便我可以访问存储库上的 git 操作?

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

新的 GitHub 操作(版本 2)使用 CodeStarSourceConnection。因此,我们只需要在管道的源阶段指定 CodeStarSourceConnection [1] 源操作提供程序。 CloudFormation 也支持 AWS::CodeStarConnections::Connection 资源 [2]。您可以引用现有连接的 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] 中的连接使其状态可用。连接可用后,您可以将 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