我正在为我的 CI/CD 链使用 Argo Events 和 Argo Workflow,它工作得非常整洁。但是我在为我的 mono repo的GitHub webhook 有效负载设置数据过滤器时遇到了一些麻烦。如果文件在某个子路径中发生更改,我试图让传感器仅触发定义的工作流程。有效负载包含添加、删除、修改三个字段。那里列出了在此提交中更改的文件(webhook-events-and-payloads#push)。我正在寻找的路径是service/jobs/*和service/common*/*。我定义的过滤器是: - path: "[commits.#.modified.#(%\"*service*\")#,commits.#.added.#(%\"*service*\")#,commits.#.removed.#(%\"*service*\")#]"
type: string
value:
- "(\bservice/jobs\b)|(\bservice/common*)"我在一个很小的Go脚本中验证了我的过滤器,因为Argo Events 使用gjson来应用数据过滤器。package mainimport ( "github.com/tidwall/gjson" "regexp")const json = `{ "commits": [ { "added": [ ], "removed": [ ], "modified": [ "service/job-manager/README.md" ] }, { "added": [ ], "removed": [ "service/joby/something.md" ], "modified": [ "service/job-manager/something.md" ] }, { "added": [ ], "removed": [ "service/joby/something.md" ], "modified": [ "service/joby/someother.md" ] } ], "head_commit": { "added": [ "service/job-manager/something.md" ], "removed": [ "service/joby/something.md" ], "modified": [ "service/job-manager/README.md" ] } }`func main() { value := gjson.Get(json, "[commits.#.modified.#(%\"*service*\")#,commits.#.added.#(%\"*service*\")#,commits.#.removed.#(%\"*service*\")#]") println(value.String()) matched, _ := regexp.MatchString(`(\bservice/job-manager\b)|(\bservice/common*)`, value.String()) println(matched) // string is contained?}该脚本给了我预期的结果。但是对于相同的 webhook 有效负载,在将数据过滤器添加到传感器时不会触发工作流。有人有什么想法吗?
1 回答
临摹微笑
TA贡献1982条经验 获得超2个赞
路径应以
body.
值应添加转义特殊字符
\\
所以数据过滤器应该是
- path: "[body.commits.#.modified.#(%\"*service*\")#,body.commits.#.added.#(%\"*service*\")#,body.commits.#.removed.#(%\"*service*\")#]" type: string value: - "(\\bservice/jobs\\b)|(\\bservice/common*)"
- 1 回答
- 0 关注
- 75 浏览
添加回答
举报
0/150
提交
取消