-
-
Save ajliv/7bd9b9ae4961400afc4c8c5ce1beedbb to your computer and use it in GitHub Desktop.
Selectively triggering a GitHub sourced CodePipeline (only for one file)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# CodePipeline by default runs an execution whenever any change is detected in the configured source repository | |
# We can use a CodePipeline Webhook resource to filter such executions. | |
# | |
# This is a snippet that would be part of a CloudFormation template containing | |
# a CodePipeline resource (AWS::CodePipeline::Pipeline), named CodePipeline in this case, and | |
# assumes the GutHub OAuth token is available in the parameter GitHubOAuthToken. | |
# Typically a CodePipeline Webhook only contains the $.ref filter to check for | |
# the desired branch. | |
# However we can add up to 4 more filters, each of which can query the incoming webhook payload from Github. | |
# Such payloads are of the form: | |
# { | |
# ... | |
# "commits": [ | |
# { | |
# ... | |
# "added": [ | |
# "addedfile1.txt", | |
# ... | |
# ], | |
# "removed": [ | |
# | |
# ], | |
# "modified": [ | |
# "README.md", | |
# "modifiedfile2.txt" | |
# ] | |
# } | |
# ], | |
# ... | |
# } | |
# ... and so we can query the commits object in a JSON Path expression. | |
# The example here will therefore only trigger a pipeline if the README.md file is updated | |
# References: | |
# https://docs.aws.amazon.com/codepipeline/latest/APIReference/API_WebhookDefinition.html | |
# https://docs.aws.amazon.com/codepipeline/latest/APIReference/API_WebhookFilterRule.html | |
GithubWebhook: | |
Type: 'AWS::CodePipeline::Webhook' | |
Properties: | |
RegisterWithThirdParty: 'true' | |
Authentication: GITHUB_HMAC | |
AuthenticationConfiguration: | |
SecretToken: !Ref GitHubOAuthToken | |
Filters: | |
- JsonPath: "$.ref" | |
MatchEquals: refs/heads/{Branch} | |
# Only trigger pipeline if README is updated | |
Filters: | |
- JsonPath: "$.commits[*].*[?(@ == 'README.md')]" | |
MatchEquals: README.md | |
TargetPipeline: !Ref CodePipeline | |
TargetAction: Source | |
TargetPipelineVersion: !GetAtt CodePipeline.Version |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment