I would like to be able to set the webhook filters on the source action in my code pipeline
I want to trigger the pipeline only when certain files are changed (aka the purpose of the filters)
Codebuild module seems to support setting webhook filters, but I cannot find a way to do this on the GitHubSourceAction that I use as the source for my code pipelines. Looking at the code for codepipeline-actions module, it seems like the webhook is set here. Maybe you could re-use some of the Codebuild classes to implement this for Codepipeline source actions too?
This is a :rocket: Feature Request
maybe this is harder than I thought.. codepipeline webhook filters seem to work differently from codebuild ones?
edit:
I actually wanted to trigger based on file paths modified, but it appears that this is not supported at all in codepipeline since "matchEquals" doesnt support regex? Then I assume the reason you don't support this feature is because it doesn't really allow you to do much else than what setting "branch" does.. Am I right?
Hey @fongie ,
does the GitHub webhook API actually contain the modified files when it does the call?
Thanks,
Adam
Hi!
Yes, I'm pretty sure it does. By looking at my last webhook invocation from a CDK-created pipeline, I think you should be able to get the needed information from the "commits"
key, under the subkeys "added"
, "removed"
, and "modified"
.
This is the structure from my latest webhook invocation:
{
"ref": "..",
"before": "sha..",
"after": "sha..",
"repository": {
"stuff": "..lots of stuff"
},
"pusher": {
"name": "fongie",
"email": ".."
},
"organization": {
"stuff": "..lots of stuff"
},
"sender": {
"stuff": "..lots of stuff"
},
"created": false,
"deleted": false,
"forced": false,
"base_ref": null,
"compare": "...",
"commits": [
{
"id": "sha",
"tree_id": "id",
"distinct": true,
"message": "readd tsconfig",
"timestamp": "2020-09-09T19:03:23+02:00",
"url": "url",
"author": {
"name": "fongie",
"email": "..",
"username": "fongie"
},
"committer": {
"name": "fongie",
"email": "..",
"username": ".."
},
"added": [
"tsconfig.json"
],
"removed": [
],
"modified": [
".gitignore"
]
}
],
"head_commit": {
"id": "id",
"tree_id": "id",
"distinct": true,
"message": "readd tsconfig",
"timestamp": "2020-09-09T19:03:23+02:00",
"url": "url",
"author": {
"name": "fongie",
"email": "..",
"username": "fongie"
},
"committer": {
"name": "fongie",
"email": "..",
"username": "fongie"
},
"added": [
"tsconfig.json"
],
"removed": [
],
"modified": [
".gitignore"
]
}
}
Might not be the best example, but the full file path shows up (it could be src/lib/my-thing.ts
for example)
In fact, I created a jsonpath expression that could select the "added", "removed", and "modified" files without much difficulty as a long list (.. I may have gotten rid of it when I found out it wouldnt work though) as described here, and then what remains would be simply to match each with a regex. But then I understood that "matchEquals" doesnt support regex or glob type expressions, only exact matches (?) which makes me think that this is not something we could solve "just" using CDK?
It would be really nice if you could though!
I have worked around this by creating my own construct which creates a pipeline and a codebuild project "in front" of the pipeline with the filters I wanted
but it would of course be nice if you could specify the filters right away on the pipeline instead =)
It would be very good if the webhook filter for aws cdk codepipeline supported 'pattern' and 'excludeMatchedPattern' like codebuild webhook does. https://docs.aws.amazon.com/codebuild/latest/APIReference/API_WebhookFilter.html
Currently only jsonPath and matchEquals properties are supported with aws cdk codepipeline.
MatchEquals takes a simple string property which makes it impossible to match paths or file patterns from jsonPath output.
Most helpful comment
I have worked around this by creating my own construct which creates a pipeline and a codebuild project "in front" of the pipeline with the filters I wanted
but it would of course be nice if you could specify the filters right away on the pipeline instead =)