Trigger a Task With a Webhook
Webhooks provide a highly convenient way to execute a task automatically when a specific URL gets hit. Common use cases are:
- Deploy an application whenever a commit is performed in your Github code repository
- Run integration testing on each commit
- etc.
In this how-to we will focus on setting up a webhook in a devo.ps task and associate it with GitHub.
(Pre-requisite) You need to have defined a task with the steps you want to run automatically.
From your profile page, click on the repository you want to use. You will land on the "Home" section of the repository.
The Home section shows all the servers and tasks you have defined in that specific repository and their status.
Click on the task you want to trigger via a GitHub webhook, and click on the edit icon.
In the editor, edit your task and add a new webhook trigger like the following:
id: my-task name: My Task type: task triggers: webhooks: # This URL is publicly accessible, you may want to randomize it instead # - path: SuPeRr4ndOm - path: my/super/secret/url steps: ...
The path you enter in your task will be reachable via the following URL: https://wh.devo.ps/username/repo/path. You will see the exact URL path when you save the task and see the details of the task.
You can specify multiple paths for the various clients you may want to use; for example a GitHub dedicated URL, a Jenkins URL, etc.
This task will be triggered by a POST HTTP request on the URL previously defined.
Go in your GitHub account, and select the repository you want to set the webhook on.
Click on the settings page, then Webhooks and Services tabs.
Note; you need to be administrator of that GitHub repository to access the settings page. If you are not, you may want to contact the admins and get them to add the webhook.
Click on "Add webhook", and paste the webhook URL in the "Payload URL" text box. Keep the "Content type" as
application/json
and leave the "Secret" blank. You probably want to keep the rest as default, unless you know what you are doing; only trigger the webhook on "push event".You may be prompted for your GitHub password to perform this operation.
You can also refer to the official GitHub documentation about webhook.
Finally Click the "Add Webhook" button and you are set!
Any future commit on your GitHub repository will automatically trigger a webhook to your devo.ps account and get the task to start in a matter of seconds.