Difference between revisions of "Gitea/Jenkins: Setting up Webhooks"

From Gcube Wiki
Jump to: navigation, search
(Build project configuration)
Line 1: Line 1:
 
= What is a webhook? =
 
= What is a webhook? =
A webhook is a mechanism to automatically trigger the build of a Jenkins Pipeline project upon a commit pushed in the Git [Git_repository|repository]].
+
A webhook is a mechanism to automatically trigger the build of a Jenkins Pipeline project upon a commit pushed in a Git [[Git_repository|repository]].
  
 
This guide details the steps to have Jenkins automatically create a build if it detects changes to a Gitea repository.  This can be a very useful improvement to continuous integration setup with Jenkins because this method is only telling Jenkins to attempt a new build when a change is detected rather than polling on an interval, which can be a very inefficient.
 
This guide details the steps to have Jenkins automatically create a build if it detects changes to a Gitea repository.  This can be a very useful improvement to continuous integration setup with Jenkins because this method is only telling Jenkins to attempt a new build when a change is detected rather than polling on an interval, which can be a very inefficient.

Revision as of 04:41, 11 May 2019

What is a webhook?

A webhook is a mechanism to automatically trigger the build of a Jenkins Pipeline project upon a commit pushed in a Git repository.

This guide details the steps to have Jenkins automatically create a build if it detects changes to a Gitea repository. This can be a very useful improvement to continuous integration setup with Jenkins because this method is only telling Jenkins to attempt a new build when a change is detected rather than polling on an interval, which can be a very inefficient.

Gitea Plugin on Jenkins

This plugin allows to configure Jenkins to talk to Gitea.

Installation

In Jenkins: download and install the Gitea plugin in Jenkins.

Go in the page: Manage Jenkins -> Manage Plugins -> Available -> Gitea plugin

And install the plugin.

Configuration

JenkinsGiteaPluginConfig.png

Build project configuration

In Jenkins, on the project settings page "Source Code Management" set:

  • option to "Git",
  • provide URL to your repo (e.g. https://code-repo.d4science.org/gCubeSystem/gxRest.git),
  • set the credentials to git.gcube,
  • specify */master as branch to build,
  • and in "Poll triggers" section check "Poll SCM" option with no schedule defined. This setup basically tells Jenkins to poll your Gitea repo only when requested via the webhook.

JenkinsSourceCodeManagement.png

Webhook on the Gitea repository

In Gitea: under repo -> Settings -> Webhooks, add new webhook, set the URL to http://jenkins.d4science.org/gitea-webhook/post?job=<project>, where project is the name of the project in Jenkins to build. Then, clear the secret (leave it blank).

At this point clicking on "Test Delivery" button should produce a successful delivery attempt (green checkmark).

If your test deliveries fail, try to see if you can POST to Jenkins webhook URL (http://jenkins.d4science.org/gitea-webhook/post). E.g. using [[1]] or with curl:

curl -vvv -H "Content-Type: application/json" -H "X-Gitea-Event: push" -X POST http://jenkins.d4science.org/gitea-webhook/post -d "{}"

Correct response should be just plain "Processed" string. If you get something else, post it here.