简体   繁体   中英

how to trigger gitlab webhook on merge only

Thanks for any help in advance,

I currently have a Gitlab Webhook successfully triggering a Jenkins job on the 'merge request events' option: enter image description here

However, this triggers the Jenkins job for each stage of the merge request, so whenever a request is created, updated, merged and closed - the URL is triggered and the Job is run for each of these stages.

Is it possible to limit the Webhook to **only ** trigger on a merge approval (so when the merge button is pressed only). enter image description here

the Webhook payload passes in each stage under the "action" tag, but only care about the "merged" action. As for the creation, update or closure of the request, I dont need the job to run at these stages.

.. I have tried to resolve this at the Jenkins side - I'm using the Generic Webhook Trigger Plugin and i'm passing in the JSON payload for the trigger - so I can manipulate the job per "action" value being sent though.

However, this was insufficient as the Gitlab Webhook will always trigger from the Gitlab side per 'merge event', resulting in multiple calls to the Jenkins job.

I have found the answer, this comes in the way of the Generic Webhook Trigger Plugin.

As I have pulled the 'action' variable from the Gitlab Webhook payload:

adding Json payload variable

I can now add this variable to the "Optional Filter" within the same Jenkins plugin:

use the variable as a filter with the relevant expression

here I can re-use the merge action variable and look for the passed in value of "merge".

Now my job will only run if this expression if found within the variable i am pulling though.

Also.. I can add multiple variables into the 'Optional Filter' and make them dependant on the expressions being passed in.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM