简体   繁体   中英

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

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 ). Eg 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!

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 - eg

  • 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.

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.

You can use the Generic Webhook Trigger Plugin .

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM