我通过使用regexpFilterExpression
.
首先,您需要将推送事件所针对的分支名称放入ref
通过将其添加到GenericTrigger
类中来命名的变量中:
genericVariables: [
[key: 'ref', value: '$.ref'],
[key: 'commit_titles', value: '$.commits[*].title']
]
现在我们需要触发器有效负载中提交的所有标题,因此为它添加另一个变量
[key: 'commit_titles', value: '$.commits[*].title']
然后我们需要通过在类中定义regexpFilterText
属性来组装将应用过滤器的字符串GenericTrigger
...
regexpFilterText: 'BRANCH: $ref COMMIT_TITLES: $commit_titles END',
...
变量将被替换。
然后是时候定义实际的过滤器了
...
regexpFilterExpression: "BRANCH: refs/heads/master COMMIT_TITLES: .*?(Merge pull request).*? END"
...
完整示例:
properties ([
pipelineTriggers([
[$class: 'GenericTrigger',
genericVariables: [
[key: 'ref', value: '$.ref'],
[key: 'commit_titles', value: '$.commits[*].title']
],
token: 'my secret token',
causeString: 'Triggered because of $commit_titles in branch $ref',
printContributedVariables: true,
printPostContent: true,
silentResponse: false,
regexpFilterText: 'BRANCH: $ref COMMIT_TITLES: $commit_titles END',
regexpFilterExpression: "BRANCH: refs/heads/master COMMIT_TITLES .*?(Merge pull request).*? END"
]
])
])