LoginSignup
11
6

More than 1 year has passed since last update.

CloudFormation CodePipeline で Github v2 用コネクションを使ってGithubからソースコードを取得する

Posted at

前置き

v1の方法はいくらでも見つかるのですが、v2の方法が、推奨だというのにも関わらずまったく見当たらないのでまとめてみました。

やり方

結論からいえば、以下に設定値が載っています。

なんだ、CodeStarSourceConnection って。OwnerもGithubじゃないんかい。
これにたどり着くまでが長かった..

せっかくなんでやることをまとめてみます。

  • コネクションを作成する
    これは認証もからむのでCloudFormationでやる必要はないと思います。私はAWSコンソールからやりました。

  • コネクションを使うポリシーを作成する。
    これもIAMのコンソールから作成しちゃいました。CloudFormation使え > 自分
    作成したポリシーをCodePipeline用のRoleにアタッチしときます。

{
    "Version": "2012-10-17",
    "Statement": [
      {
        "Sid": "ConnectionsFullAccess",
        "Effect": "Allow",
        "Action": [
            "codestar-connections:CreateConnection",
            "codestar-connections:DeleteConnection",
            "codestar-connections:UseConnection",
            "codestar-connections:GetConnection",
            "codestar-connections:ListConnections",
            "codestar-connections:TagResource",
            "codestar-connections:ListTagsForResource",
            "codestar-connections:UntagResource"
        ],
        "Resource": "*"
     }
   ]
}

  • CloudFormationでのSource取得ステージの書式
  CodePipeline:
    Type: "AWS::CodePipeline::Pipeline"
    DependsOn: EcsService
    Properties:
      Name: !Ref AWS::StackName
      RoleArn: !GetAtt CodePipelineRole.Arn
      ArtifactStore:
        Location: !Ref CodePipelineS3Bucket
        Type: S3
      Stages:
        - Name: Source
          Actions:
            - InputArtifacts: []
              Name: Source
              ActionTypeId:
                Category: Source
                Owner: AWS
                Version: "1"
                Provider: CodeStarSourceConnection
              OutputArtifacts:
                - Name: SourceArtifact
              Configuration:
                FullRepositoryId: "OrganizationName/RepositoryName"
                ConnectionArn: "arn:aws:codestar-connections:ap-northeast-1:xxxxxxxxxxxxxxxxxxxxxx" #上記で作成したConnectionのARN
                BranchName: "develop"
                DetectChanges: "false"
              RunOrder: 1

参考になれば。

11
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
6