gitea和jenkins webhook [英] gitea and jenkins webhook

查看:1574
本文介绍了gitea和jenkins webhook的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在测试Gitea,并希望它触发Jenkins构建,非常基本的用例.我知道可以使用现有的GOGs webhook插件,但最近还发现Jenkins也有一个Gitea插件.

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.

在GOGS情况下,您可以通过以下方式致电詹金斯: http://localhost:8080/gogs-webhook/?job = job_name

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.

问题是没有有关Gitea插件的文档,但是根据源代码,URL应该是:

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看到了推送活动,并将信息发布到Jenkins webhook
  2. Jenkins Gitea webhook看到了POST,并使用该信息从Gitea获取了新的源代码.

问题是gitea插件如何知道要执行的作业?您如何指定呢?现在,我可以看到gitea通过上述URL将POST发送到Jenkins,但没有任何反应,Jenkins日志也没有任何信息来了解其失败的原因.

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.

我在这里遇到一个问题,在将生成的公共SSH密钥复制到Gitea用户帐户后,Jenkins仍然无法访问回购以便使用Pipeline Editor.不知道我在这里缺少什么,因为我能够从本地主机(在Docker环境之外)完美地推入/拉出,并检查容器的确也可以完美地看到彼此....

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

谢谢

推荐答案

我已经成功使用相对较新的版本成功配置了Jenkins/Gitea组合(我都使用了官方的基于Alpine的Docker容器).我使用了此Gitea问题作为指南.我没有在Jenkins中使用Gogs插件,仅在Gitea插件中使用了.我也不使用管道,只使用经典的手动配置作业.

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.

在Jenkins中:在作业设置页面上,将源代码管理"选项设置为"Git",提供您的仓库的URL(

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.

在Gitea中:在repo-> Settings-> Webhooks下,添加新的webhook,将URL设置为 http://jenkins_url.your.org/gitea-webhook/post ,然后清除秘密(将其保留为空白).

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

如果测试交付失败,请尝试查看是否可以发布到Jenkins webhook URL( http ://jenkins_url.your.org/gitea-webhook/post ).例如.使用邮递员或使用curl:

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.

关于您关于 Jenkins如何知道要从事的工作的问题,我的理解是 POST请求正文包含到存储库/分支的链接,并且Jenkins在内部进行查找以查找引用此存储库的作业(您在上面的作业设置页面中定义的内容). 此Jenkins Wiki页面详细介绍了通用钩子,还有此答案,其中的其他链接可能会解释一点点掩盖下发生的事情.

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.

要调试一些东西,您可以将gitea存储库(或组织)设置中的最近的交付"(整个发布请求以及响应都可单击!)作为

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!

这篇关于gitea和jenkins webhook的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆