Skip to content

Jenkins Plugin that can receive any HTTP post request like webhook, parse the json body, extract values using JSONPath and trigger a jenkins job with those values as job parameters.

Notifications You must be signed in to change notification settings

utec/easy-webhook-plugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Easy Webhook Plugin

Plugin that can receive HTTP post request from bitbucket , gitlab y github(coming sooon), parse the json body, extract values using JSONPath & groovy and trigger a jenkins job with those values as job parameters.

How it works?

When a event is triggered in your git repository manager (bitbucket, github, gitlab) or another platform, a jenkins job will be launched with following parameters:

Build plugin from source code

Requirements:

  • Java 8
  • Maven

Steps

Execute:

mvn clean package

If no error, you must see a file called easy-webhook-plugin.hpi in maven target folder.

Plugin installation

Plugin configuration

  • After success installation , go to Jenkins > Manage Jenkins > Configure System > Configure Easy WebHook Plugin
  • Add the secret key and save. This value helps to hide and protect your public webhook url

That's all. You have a new public endpoint in your jenkins, ready to use as webhook in your git platform provider.

Basic job jenkins

In order to test this plugin, we need a minimal jenkins job. Pipeline job is recommended.

node {
   echo 'New build detected with this incoming parameters: '+params
}

For demo purposes, we will call hello_word_job to this job.

Usage

After a success installation and configuration you could have this scenario :

Parameter Description Example
jenkins host ip or public domain my_jenkins.com or localhost:8080
easy webhook secret key plugin configuration 123456789
scmId one of the well known scm: gitlab, bitbucket or github gitlab
jobId name of any existent jenkins job hello_word_job

With the previous parameters, your webhook url will be:

http://my_jenkins.com/easy-webhook-plugin-123456789/?scmId=gitlab&jobId=hello_word_job

Test using curl

In order to test this plugin, we will simulate a gitlab push event using curl.

For this test, we need a exact gitlab webhook json sample. Here an example

Download this json and save in some file like: /tmp/gitlab_webhook.json

I everything is good, you can exec this curl:

curl -d @/tmp/gitlab_webhook.json \
-H "Content-Type: application/json" \
-X POST "http://my_jenkins.com/easy-webhook-plugin-123456789/?scmId=gitlab&jobId=hello_word_job"

If you go to your jenkins home, you must see a new build execution in your hello_word_job job

Using Bitbucket, Github or Gitlab

If the previous test with curl worked, your webhook is ready to use :D in gitlab for example.

Create some git repository and add the following url as webhook for push events. Check this post to get a detailed guide for bitbucket, github and gitlab.

The url to register will be something like this:

http://my_jenkins.com/easy-webhook-plugin-123456789/?scmId=gitlab&jobId=hello_word_job Or if you want, add new http query parameter like notificationUsers

http://my_jenkins.com/easy-webhook-plugin-123456789/?scmId=gitlab&jobId=hello_word_job&notificationUsers=jane.doe@blindspot.com

Finally, just push some change and go to your Jenkins to see the new build in progress :D

Get hacks from

Coming soon

  • Unit Tests
  • github json path expressions
  • Add to Jenkins official site
  • Install from available plugins in Jenkins configurations (coming soon)

Contributors

Thanks goes to these wonderful people :


Richard Leon

About

Jenkins Plugin that can receive any HTTP post request like webhook, parse the json body, extract values using JSONPath and trigger a jenkins job with those values as job parameters.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Languages