Jenkins - To trigger pipeline only for event failed or successful for jenkins webhook trigger

86 Views Asked by At

I want to trigger a pipeline for cases where it only triggers two cases when the event received is failed or successful using the Jenkins webhook trigger. enter image description here

for eg: If I have an event log as JSON like the one below

{"involvedObject":{"kind":"HelmRelease","namespace":"flux-system","name":"my-release","uid":"1f86243d-bcd9-4e0a-b078-c9df8f9441ac","apiVersion":"helm.toolkit.fluxcd.io/v2beta1","resourceVersion":"1466894"},"severity":"info","timestamp":"2023-10-25T06:20:18Z","message":"Helm upgrade succeeded","reason":"info","metadata":{"revision":"6.5.2"},"reportingController":"helm-controller","reportingInstance":"helm-controller-578bd944df-m9sgx"}

I want this event to filter only messages using regexp "Helm upgrade succeeded" or "Helm upgrade failed". If any other filter comes apart of this message it should not trigger my pipeline.

Any help over regexp for this would be great. Tried ($failed|$success) , (failed|success).. dint work Note: I am using the Jenkins webhook Trigger plugin for the above use case and using an optional filter under this plugin.

1

There are 1 best solutions below

0
Barel elbaz On

Install the generic webhook trigger plugin and try this out

pipeline {
    agent any
    triggers {
        GenericTrigger(
               genericVariables: [
                       [key: 'payload', value: '$'],
                       [key: 'message', value: '$.message'],
               ],
               regexpFilterText: '$message',
               regexpFilterExpression: '(Helm upgrade succeeded)|(Helm upgrade failed)'
               causeString: 'Triggered by helm ', //give it any cause you want
               token: "<your-token>",
        )
    }