Generic Webhook Trigger1.30Minimum Jenkins requirement: 2.7.4ID: generic-webhook-trigger
This is a Jenkins plugin that can:
- Receive any HTTP request, JENKINS_URL/generic-webhook-trigger/invoke
- Extract values
- Contribute those values as variables to the build
There is an optional feature to trigger jobs only if a supplied regular expression matches the extracted variables. Here is an example, let's say the post content looks like this:
Then you can have a variable, resolved from post content, named reference of type JSONPath and with expression like $.ref .
The optional filter text can be set to $reference and the filter regexp set to ^(refs/heads/develop|refs/heads/feature/.+)$ to trigger builds only for develop and feature-branches.
This means it can trigger on any webhook, like:
You may want to report back to the invoking system. HTTP Request Plugin is a very convenient plugin for that.
If a node is selected, then all leafs in that node will be contributed. If a leaf is selected, then only that leaf will be contributed.
There are websites to help fiddle with the expressions. You may want to checkout:
- This website to fiddle with JSONPath.
- This website to fiddle with XPath.
- This website to fiddle with regexp.
When using the plugin in several jobs, you will have the same URL trigger all jobs. If you want to trigger only a certain job you can:
- Use the
token-parameter and have different tokens for different jobs.
- Add some request parameter (or header, or post content) and use the regexp filter to trigger only if that parameter has a specific value.
The original use case was to build merge/pull requests. You may use the Git Plugin as described in this blog post to do that. There is also an example of this on the Violation Comments to GitLab Plugin page.
There is a special
token parameter. When supplied, it is used with BuildAuthorizationToken to authenticate.
It might be a good idea to have a different token for each job. Then only that job will be visible for that request. This will increase performance and reduce responses of each invocation.
The token can be supplied as a:
Authorization header of type Bearer :
It's probably easiest to do with curl. Given that you have configured a Jenkins job to trigger on Generic Webhook, here are some examples of how to start the jobs.
This may start your job, if you have enabled "Allow anonymous read access" in global security config. If it does not, check the Jenkins log. It may say something like this.
And to authenticate in the request you may use a *token*, or try this:
If you want to trigger with some post content, curl can dot that like this.
If you need the resolved values in pre build steps, like git clone, you need to add a parameter with the same name as the variable.
This plugin can be used with the Job DSL Plugin. There is also an example in Violation Comments to GitLab Plugin wiki page.
Pipeline multibranch example
It can be used with the Pipeline Multibranch Plugin.
It can be triggered with something like:
And the job will have this in the log: