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:
- Gitea sees the push activity and POSTs the info to Jenkins webhook
- 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
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:
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!
You can use the Generic Webhook Trigger Plugin.
Use the token-feature and have a different token for each job.
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:
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.
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
), triggeringhttp://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), orhttp://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.