Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gitea and jenkins webhook

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

like image 509
fobius Avatar asked Jan 18 '18 07:01

fobius


2 Answers

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!

like image 122
KMZ Avatar answered Sep 17 '22 15:09

KMZ


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.

like image 35
gilesgas Avatar answered Sep 17 '22 15:09

gilesgas