Jenkins - Gogs/Github Webhook
☰ Table of Content
How to set them up.
Jenkins Plugins
In Manage Jenkins
-> Manage Plugins
-> Available
, install the required plugins.
Git Platform | Plugins |
---|---|
Github | GitHub plugin |
Gogs | Gogs plugin |
1. GitHub Webhook
Before setting up github webhook, check your Jenkins end point(URL) is IPv4 reachable. At the time of this post (2020-06-16), GitHub webhook does not work with IPv6 only URL.
1.1 On Jenkins
- Go to or create your freestyle project
- For existing project, go to
Configure
Source Code Management
, selectGit
Repositories
: Fill in your repository URL, this can be HTTP(S) with or without.git
at the end, orSSH
clone URL.Credentials
None
if repo is public and HTTP(S) url is used above.- You will need Github token for private repo HTTP(s) url.
- You will need ssh key for SSH url, even repo is public.
Build Triggers
, check markGitHub hook trigger for GITScm polling
- Click
Apply
.
1.2 On GitHub
- Go to your repository
- Go to
Settings
- Go to
Webhooks
- Go to
Add webhook
- Fill in following
Payload URL
:https://<your jenkins url>/github-webhook/
Content type
: bothapplication/json
andapplication/x-www-from-urlencoded
work.Secret
: Leave empty.Just the push event
: This is properly what you want.Active
: Should be check marked already.
- Click
Add webhook
You will be back to Webhooks
page and see your new webhook listed there. There will be a green check mark if webhook is working.
2. Gogs Webhook
2.1 On Jenkins
- Go to or create your freestyle project
- For existing project, go to
Configure
Gogs Webhook
- Check mark
Use Gogs secret
and fill inSecret
if you are going to use secret.
- Check mark
Source Code Management
, selectGit
Repositories
: Fill in your repository URL, this can be HTTP(S) with or without.git
at the end, orSSH
clone URL.Credentials
None
if repo is public and HTTP(S) url is used above.- You will need Gogs token for private repo HTTP(s) url.
- You will need ssh key for SSH url, even repo is public.
Build Triggers
, check markBuild when a change is pushed to Gogs
- Click
Apply
.
2.2 On GitHub
- Go to your repository
- Go to
Settings
- Go to
Webhooks
- Go to
Add a new webhook:
, chooseGogs
- Fill in following
Payload URL
:https://<your jenkins url>/gogs-webhook/?job=<project name / pipeline name>
- Gogs webhook will fail without
?job=<project name /pipeline name>
- Gogs webhook will fail without
Content type
:application/json
. Jenkins Gogs plugin does not supportapplication/x-www-from-urlencoded
.Secret
: Fill in same secret as in Jenkins if used.Just the push event
: This is properly what you want.Active
: Should be check marked already.
- Click
Add webhook
- You will be back to
Webhooks
page and see your new webhook listed there. Click the new webhook. - Click
Test Delivery
to verify.
John Siu
Update: 2020-08-28