Open fongie opened 4 years ago
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 =)
edit: I have open sourced a construct that does this here available on npm, or you can see some quick code at this gist if you want to write your own :)
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.
hey, are there any updates or plans on this?
Hey @adriantaut,
unfortunately, this first needs to be done in CodePipeline first (this is a missing capability currently).
If you have Premium Support, I believe you can open a Feature Request to the CodePipeline service.
Thanks, Adam
@skinny85 Thank you for your suggestion, Adam! Will try to get in touch with the AWS team. Cheers! 👍
https://blog.cuckoo.org/aws-pipelines-with-github-release-trigger-in-cdk - which shows setting of the webhook filters - this also relates to https://github.com/aws/aws-cdk/issues/8111
We also need a way to match booleans, because in the GitHub release event, the properties draft
and prerelease
are boolean values which indicate the type of the release. In my case I am only interested to trigger a pipeline if the release is not a draft or pre-release.
This issue has received a significant amount of attention so we are automatically upgrading its priority. A member of the community will see the re-prioritization and provide an update on the issue.
I would like to be able to set the webhook filters on the source action in my code pipeline
Use Case
I want to trigger the pipeline only when certain files are changed (aka the purpose of the filters)
Proposed Solution
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?
Other
This is a :rocket: Feature Request