I solved it by using the regexpFilterExpression.
First you will need to put the branch name for which the push event came for into a variable named ref by adding this to the GenericTrigger class:
genericVariables: [
[key: 'ref', value: '$.ref']
]
Now we need all the titles from the commits that were in the trigger payload, so add another variable for it
,[key: 'commit_titles', value: '$.commits[*].title']
Then we need to assemble the string on which the filter will be applied on by defining the regexpFilterText property in GenericTrigger class
...
regexpFilterText: 'BRANCH: $ref COMMIT_TITLES: $commit_titles END',
...
Variables will be substituted.
Then it is time to define the actual filter
...
regexpFilterExpression: "BRANCH: refs/heads/master COMMIT_TITLES: .*?(Merge pull request).*? END"
...
Complete example:
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"
]
])
])