1

我创建了一个堆栈,其中有用于创建管道的资源,每次在“master”分支上进行推送时都会启动管道:

  CodeCommitBranch:
    Type: String
    Description: branch name
    Default: master
    AllowedValues:
      - develop
      - release
      - master

CodePipeline:
    Type: 'AWS::CodePipeline::Pipeline'
    Properties:
      Name: !Sub '${Constructor}-${ApplicationID}-codepipeline'
      ArtifactStore:
        Location: !Ref CodePipelineS3BucketName
        Type: S3
      RestartExecutionOnUpdate: true
      RoleArn: !Sub 'arn:aws:iam::${AWS::AccountId}:role/${CodePipelineRoleName}'
      Stages:
        - Name: Source
          Actions:
            - Name: Source
              ActionTypeId:
                Category: Source
                Owner: AWS
                Provider: CodeCommit
                Version: 1
              RunOrder: 1
              OutputArtifacts:
                - Name: SourceArtifact
              Configuration:
                BranchName: !Ref CodeCommitRepoBranch
                PollForSourceChanges: false
                RepositoryName: !GetAtt 
                  - CodeCommitRepo
                  - Name
        - Name: Deploy-Dev
          Actions:
            - Name: Deploy-Dev
              ActionTypeId:
                Category: Build
                Owner: AWS
                Provider: CodeBuild
                Version: 1
              RunOrder: 2
              InputArtifacts:
                - Name: SourceArtifact
              OutputArtifacts:
                - Name: DeployArtifactDev
              Configuration:
                ProjectName: !Ref CodeDeployDev
        - Name: Deploy-Int
          Actions:
            - Name: IntPromotionApproval
              ActionTypeId:
                Category: Approval
                Owner: AWS
                Provider: Manual
                Version: 1
              RunOrder: 3
            - Name: Deploy-Int
              ActionTypeId:
                Category: Build
                Owner: AWS
                Provider: CodeBuild
                Version: 1
              RunOrder: 31
              InputArtifacts:
                - Name: SourceArtifact
              OutputArtifacts:
                - Name: DeployArtifactInt
              Configuration:
                ProjectName: !Ref CodeDeployInt

我想知道是否可以在“开发”分支上发生推送时在启动同一管道的同一资源中添加一个操作。因此,最终管道在“master”和“develop”被推动时开始。

4

2 回答 2

0

AWS CodePipeline 尚不支持多分支管道配置。因此,理想情况下,您需要为您的develop分支创建另一个管道。

您的管道配置了 CloudWatch 事件。ACloudWatch event rule为您的管道自动配置

{
  "source": [
    "aws.codecommit"
  ],
  "detail-type": [
    "CodeCommit Repository State Change"
  ],
  "resources": [
    "arn:aws:codecommit:us-west-2:80398EXAMPLE:MyTestRepo"
  ],
  "detail": {
    "referenceType": [
      "branch"
    ],
    "referenceName": [
      "master",
      "develop"
    ]
  }
}

如果您的管道配置了上述事件规则,则它会同时触发masterdevelop分支更改。但是您的管道是为您的主分支配置的。因此,在 CodeBuild 中,您的主分支内容将在CODEBUILD_SRC_DIR位置可用

CODEBUILD_SRC_DIR CodeBuild 用于构建的目录路径(例如,/tmp/src123456789/src)。

要为两个分支使用单个管道,那么您需要开发并在buildspec.yml文件中添加您自己的逻辑以检出到开发分支并在之后执行构建。

于 2021-06-08T03:40:59.020 回答
0

通常,您不会尝试为多个分支使用相同的管道进行构建。触发器是对触发 Cloud Watch 事件的分支的推送,该事件反过来会启动管道的其余部分。因此,尝试从许多不同的分支启动管道是不好的。

于 2021-06-07T21:29:49.337 回答