pelican
pelican

Reputation: 6224

aws codepipeline approval / review stage not building latest commit but building every single commit

I have an angular site which I build with ng build. My pipeline looks like this: source code -> Build -> Staging -> Approval -> Prod

I have an issue where if 2 commits are pushed to the repo, let's say commit 1 (c1) and commit 2 (c2), the approval step will behave like follows: It will approve c1 which will flow to the Prod stage where we do another build like this ng build --prod (to minify js files) and then the approval stage will then automatically kick off a second build for C2.

Expected behavior: I was expecting the approval to only grab the latest commit in this case let's say C2 was the latest, and only build C2, since C1 got superseded by C2.

Here's how my approval stage looks like in the template:

    Stages:
    - Name: Source
      Actions:
        - Name: Source
          ActionTypeId:
            Category: Source
            Owner: AWS
            Version: 1
            Provider: CodeCommit
          Configuration:
            RepositoryName: !Ref ProjectName
            BranchName: master
          OutputArtifacts:
            - Name: checkout
          RunOrder: 1
          RoleArn:someRole
    - Name: Dev
      Actions:
      -
        Name: staging
        ActionTypeId:
          Category: Build
          Owner: AWS
          Version: 1
          Provider: CodeBuild
        Configuration:
          ProjectName: !Ref CodeBuildProject
        RunOrder: 1
        InputArtifacts:
          - Name: checkout
        OutputArtifacts:
          - Name: buildOutput

    - Name: Approval
      Actions:
      - 
        InputArtifacts: []
        Name: pushToProd
        ActionTypeId:
          Category: Approval
          Owner: AWS
          Version: '1'
          Provider: Manual
        OutputArtifacts: []
        Configuration:
          NotificationArn: arn:aws:sns:us-east-1:########:myApprovalTopic
          ExternalEntityLink: http://myWebsite.s3-website-us-east-1.amazonaws.com/index.html
          CustomData: Approving changes to Prod
        RunOrder: 1

    - Name: Prod
      Actions:
      -
        Name: Prod
        ActionTypeId:
          Category: Build
          Owner: AWS
          Version: 1
          Provider: CodeBuild
        Configuration:
          ProjectName: !Ref CodeBuildProd
        RunOrder: 1
        InputArtifacts:
          - Name: checkout
        OutputArtifacts:
          - Name: OutputArtifactsProd

Anyone have any idea why my approval stage will NOT pick up the latest commit and only build to PROD only ONCE upon clicking that approval/review button? Instead it queues up the commits and after you click the approval button, it build all queued up commits in this case C1 and C2 instead of ONLY BUILDING THE LATEST COMMIT :(

Upvotes: 2

Views: 1573

Answers (2)

mockora
mockora

Reputation: 106

I would move the "pushToProd" action to be the first action in the "Prod" stage and disable transitions to the Prod stage. This way, even though you had 100 commits before pushing to prod, You will only need to enable stage transition on the 100th commit and only the latest revision runs through the prod stage and approve the action only for the revision that's going in to production.

Upvotes: 0

Aaron
Aaron

Reputation: 1605

Exactly one active pipeline execution can occupy a stage. When the pipeline execution corresponding to C1 enters the Approval stage, that stage is locked until you either reject or approve the pipeline execution and C2 will wait for the Approval stage (either the pipeline execution corresponding to C1 fails or exits the stage). If you want to let later builds catch up, reject the earlier build that is waiting for approval.

You should place the staging action and approval action in the same stage. This lets you approve exactly what you tested. Otherwise different pipeline executions can occupy each stage and you're not necessarily approving what you tested.

Here's an example (based on your example) that combines the Dev and Approval stages:

    Stages:
    - Name: Source
      Actions:
        - Name: Source
          ActionTypeId:
            Category: Source
            Owner: AWS
            Version: 1
            Provider: CodeCommit
          Configuration:
            RepositoryName: !Ref ProjectName
            BranchName: master
          OutputArtifacts:
            - Name: checkout
          RunOrder: 1
          RoleArn:someRole
    - Name: Dev
      Actions:
      -
        Name: staging
        ActionTypeId:
          Category: Build
          Owner: AWS
          Version: 1
          Provider: CodeBuild
        Configuration:
          ProjectName: !Ref CodeBuildProject
        RunOrder: 1
        InputArtifacts:
          - Name: checkout
        OutputArtifacts:
          - Name: buildOutput
      - 
        InputArtifacts: []
        Name: pushToProd
        ActionTypeId:
          Category: Approval
          Owner: AWS
          Version: '1'
          Provider: Manual
        OutputArtifacts: []
        Configuration:
          NotificationArn: arn:aws:sns:us-east-1:########:myApprovalTopic
          ExternalEntityLink: http://myWebsite.s3-website-us-east-1.amazonaws.com/index.html
          CustomData: Approving changes to Prod
        RunOrder: 2

    - Name: Prod
      Actions:
      -
        Name: Prod
        ActionTypeId:
          Category: Build
          Owner: AWS
          Version: 1
          Provider: CodeBuild
        Configuration:
          ProjectName: !Ref CodeBuildProd
        RunOrder: 1
        InputArtifacts:
          - Name: checkout
        OutputArtifacts:
          - Name: OutputArtifactsProd

Upvotes: 1

Related Questions