gitea and jenkins webhook
Asked Answered
B

6

10

I am testing out Gitea and would like to it to trigger a Jenkins build, pretty basic use case. I understand that there is the existing GOGs webhook pluging that can be used, but recently also found out that there is a Gitea plugin for Jenkins as well.

In GOGS case you would call Jenkins via: http://localhost:8080/gogs-webhook/?job=job_name

In the example above, obviously updating the Jenkins location and job name as needed.

The problem is there is no documentation for the Gitea plugin, but based on the source code, the URL should be:

http://jenkins-url/gitea-webhook/post

The sequence I believe should happen is the following:

  1. Gitea sees the push activity and POSTs the info to Jenkins webhook
  2. Jenkins Gitea webhook sees the POST and uses the info to grab the new source code from Gitea.

The question is how does the gitea plugin know what job to execute? How do you specify this ? Right now I can see that gitea is sending POST to Jenkins at the above URL but nothing is happening, the Jenkins logs also have no information to understand why its failing.

EDIT:

I am running into an issue here where after copying the generated public SSH key to the Gitea user account, Jenkins is still unable to access the repo in order to use Pipeline Editor. Not sure what I'm missing here as I'm able to push/pull perfectly from localhost (outside of Docker environment) and have checked that the containers indeed can see each other perfectly as well....

Thanks

Berley answered 18/1, 2018 at 7:58 Comment(3)
According to the source, it should be "gitea-webhook", gitea instead of gogs. (the plugin does not work for me either)Albertina
Phil, can you confirm if you are saying that you were not able to get it to work with the gitea plugin? From what I see out there, the gogs one does work, but I would prefer to use the gitea one if that is going to be more currentBerley
Yes exactly. And there seem no documentation whatsoever available for the gites plugin as of today.Albertina
K
14

I have managed to successfully configure a Jenkins/Gitea combo using relatively recent versions (I use official alpine-based docker containers for both). I used this Gitea issue as a guide. I didn't use the Gogs plugin in Jenkins, only the Gitea plugin. I also don't use Pipeline, only classic manually-configured jobs.

In Jenkins: on the job settings page set "Source Code Management" option to "Git", provide URL to your repo (http://gitea-url.your.org/username/repo.git), 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.

In Gitea: under repo -> Settings -> Webhooks, add new webhook, set the URL to http://jenkins_url.your.org/gitea-webhook/post, and 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_url.your.org/gitea-webhook/post). E.g. using Postman or with curl:

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

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

As for your question about how Jenkins knows what job to build, my understanding is that the POST request body contains a link to the repo/branch, and Jenkins looks this up internally to find the job that references this repo (the stuff you defined in the job settings page above). This Jenkins wiki page tells a bit more about generic hooks, and there's also this answer with further links that might explain a bit what's going on under the hood.

To debug things a bit, you can use "recent deliveries" (clickable with whole post request and also response!) from gitea repository (or organization) settings as shown in this answer. Have on mind, that gitea has its /etc/gitea/app.ini file, where ssh domain, gitea server domain and http url are specified and you specify gitea srvers in jenkins. These urls have to match for things to work!

Kronstadt answered 8/5, 2018 at 10:16 Comment(2)
I went back and checked a few things before catching your post here, and the thing that made it click was to choose the Poll SCM option leaving the timing section blank.Berley
I haven't figured it out, but the curl returns "processed" from my workstation bash shell, and nothing from my gitea server's back shell. My jenkin server is a VM and gitea server is a linux container, both are on my Proxmox hypervisor. I thought it was a plugin issue, but it appears to be between jenkins and gitea servers since it works from my workstation.Pneumograph
L
6

After trying many different guides to get webhooks to work with the Gitea plugin, I discovered that it doesn't trigger if the Gitea hostname in the json request doesn't match the one Jenkins knows.
I'm running both Jenkins and Gitea in separate Docker containers connected to the same bridge network and wanted to make them communicate using the internal hostnames. If anyone has a similar setup, try entering the public urls in Jenkins/Gitea. (There is also an option in Jenkins where you can enter an alias for the Gitea url, but that didn't work for me.)
This isn't exactly what I wanted, but it works fine this way.

Lysander answered 25/3, 2021 at 13:6 Comment(0)
A
4

When I initially installed the Gitea Plugin in Jenkins and tried configuring a webhook in Gitea to trigger a Jenkins Pipeline project (all done locally), then as @PhilW mentioned above (and assuming you're running Jenkins at http://localhost:8080), triggering http://localhost:8080/gitea-webhook/?job=job_name from Gitea didn't work for me too.

Having said that, I then installed the Gogs Plugin in Jenkins, reconfigured my webhook in Gitea http://localhost:8080/gogs-webhook/?job=job_name (noting the difference) and Jenkins built my Pipeline project without a hitch.

Also worth mentioning, as a simple dirty trick, I found that if you specify your Jenkins server's base URL (in your web browser) with the appropriate webhook appendage - e.g.

  • http://localhost:8080/gogs-webhook/ (with the Gogs Plugin installed in Jenkins and enabled), or
  • http://localhost:8080/bitbucket-hook/ (with the Bitbucket Plugin installed and enabled),

and all you get back is a blank page, this seems to indicate that the relevant webhook in Jenkins is most likely functioning as intended.

Specifying http://localhost:8080/gitea-webhook/ (with the Gitea Plugin installed and enabled) returns me an HTTP Error 404, so I suspect (just a hunch) that this plugin might have a bug or two.

Aleksandrovsk answered 7/2, 2018 at 3:38 Comment(1)
from everything I've seen, using the old Gogs plugin seems to be the way to goBerley
C
4

I use Gitea Plugin 1.0.4 on Jenkins and I have no problem with webhooks. I don't have Gog Plugin installed.

From Gitea UI (repository -> settings -> webhooks) I can manually define my webhook indicating the URL: https://my-jenkins/gitea-webhook/post

This can be tested manually, running a "Test delivery", like shown in this picture:

enter image description here

Jenkins side I have configured credential for Gitea. When Jenkins finds a project with a Jenkinsfile (I use pipeline), it automatically configures the webhook (if not present) for the repository (Gitea side).

Gitea will notify Jenkins with a POST containing a lot of information in JSON format.

Jenkins must have access to GIT repository, so you need to create credential to Git for him.

Cowlick answered 27/2, 2018 at 18:9 Comment(9)
what did you put for the webhook in gitea? when I used the URL you gave above, (my-jenkins set to localhost:8080 for testing) I got an invalid URL errorBerley
The URL I wrote above is correct, I checked it again from sourcecode: github.com/jenkinsci/gitea-plugin/blob/master/src/main/java/org/… What is your error?Cowlick
sorry, i was able to configure the webhook as you said, just wondering in this case does Jenkins Gitea webhook use the name of the repo to find the job to execute? Or how does it know what job to execute using the URL you showed above? I also updated my original post with some questions on the Jenkins configuration side, what steps do we need to take there?Berley
Added two more line to my answerCowlick
how do you specify to jenkins which task to execute ?Berley
What needs to be done is defined in the Jenkinsfile. It's executed when webhook triggers.Cowlick
what about in the case not using pipeline ?Berley
I can't help you on this. Probably on the net you can look for your answer.Cowlick
i am unable to create the pipeline successfully. my repo url is using ssh, so jenkins/blueocean generates the ssh key pair for my jenkins user. i included the public key in my Gitea user account, but it seems jenkins is unable to have access to the repo, jenkins hangs after i give the new pipeline a name. since there is no jenkinsfile present, i should be asked to create one, but jenkins does not have access to the repo even though i already added the generated public key to Gitea user accountBerley
C
4

The Gitea URL I in Jenkins configuration had was

http://192.168.1.105:3000 

and Jenkins simply ignored all the webhook triggers.

After I added the "Alias URL" for Gitea in Jenkins/configure/gitea/advanced it worked:

http://localhost:3000

fugi's answer pointed me in the right direction. I have a similar setup with both Jenkins and Gitea in separate docker containers on the same machine.

Clarhe answered 18/7, 2021 at 20:47 Comment(2)
This was also required for my setup on Microk8s using Traefik ingressRoutes as the URL provided in the POST content of Gitea was not reocgnized by Jenkins otherwise.Phyliciaphylis
Mine is even cripier... My gitea ROOT_URL does not correspond with my settings in jenkins. I corrected that to get it worked. (ROOT_URL using a global domain and jenkins using a local ip domain...)Pyretic
T
2

You can use the Generic Webhook Trigger Plugin.

Use the token-feature and have a different token for each job.

Trictrac answered 31/3, 2018 at 18:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.