Github组织中所有存储库的单一詹金斯工作 [英] Single jenkins job for all repositories in a Github organization

查看:52
本文介绍了Github组织中所有存储库的单一詹金斯工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们拥有一个Github组织,其中包含数百个由贡献者编写的存储库.我们想设置一个Jenkins服务器,该服务器对Github组织中任何存储库中的每个提交执行某些标准任务.预期的CI流程非常简单:

We own a Github organization with hundreds repositories that are authored by contributors. We would like to setup a Jenkins server that performs certain standard tasks for each commit in any of the repos in our Github organization. The intended CI flow is pretty simple:

  1. 用户对存储库myorg/foobar
  2. 进行了更改
  3. myorg的Github组织范围内的Webhook调用Jenkins服务器
  4. Jenkins运行docker命令为myorg/foobar
  5. 执行任务
  6. Jenkins将提交状态设置为待处理,包括指向命令进度输出的链接
  7. 完成后,Jenkins将最终提交状态更新为成功失败
  1. User commits a change to repo myorg/foobar
  2. Github organization-wide webhook for myorg calls the Jenkins server
  3. Jenkins runs a docker command to perform tasks for myorg/foobar
  4. Jenkins sets commit status to pending including link to command progress output
  5. Upon completion, Jenkins updates final commit status to success or failure

我是Jenkins的新手,我完全不知道需要设置哪种插件或作业类型.

I am new to Jenkins and completely lost on which Plugins or Job type I need to set this up.

我尝试为我的Github组织创建一个Jenkins"GitHub组织",但它只是告诉我此文件夹为空,没有找到包含可构建项目的存储库" .我还不清楚必须在哪里配置github组织webhook.

I tried creating a Jenkins "GitHub Organization" for my Github org, but it just tells me "This folder is empty, there are no repositories found that contain buildable projects". It's also unclear to me where the github organization webhook has to be configured.

我们不想为所有存储库设置单独的job/jenkinsfiles/webhook,而只是使用为每个存储库中的任何提交运行的标准脚本,并通过一个gh组织的webhook触发该脚本.这可能吗?

We don't want to setup separate jobs/jenkinsfiles/webhook for all repos, but simply use a standard script that gets run for any commit in each repo, and trigger this via a single gh organization webhook. Is this possible?

推荐答案

回答我自己的问题:

正如几个人指出的那样,詹金斯假设每个存储库都有一份工作. Github Organization插件不能很好地工作,因为它笨拙,需要您为每个存储库提交并维护Jenkinsfile,这正是我要避免的.

As several people had pointed out, Jenkins assumes one job per repository. The Github Organization plugin didn't work well because it is clumsy and requires you commit and maintain a Jenkinsfile to each of your repos, which is specifically what I wanted to avoid.

我不了解的关键信息是Jenkins具有出色的CLI和REST api来控制作业,并且单个作业配置可以轻松导出为简单的xml文件.

The critical piece of information that I unaware of is that Jenkins has an excellent CLI and REST api to control jobs, and a single job configuration can easily be exported as a simple xml file.

所以我要做的是通过Jenkins GUI为其中一个存储库设置Jenkins作业.然后,我编写了一个简单的REST客户端,该客户端下载此作业的config.xml,并为Github组织中的每个存储库创建或更新Jenkins作业.

So what I did is setup a the Jenkins job for one of the repos via the Jenkins GUI. Then I wrote a simple REST client that downloads the config.xml for this jobs, and creates or updates the Jenkins jobs for each of the repositories in our Github organization.

如果URL与任何存储库中的URL匹配,则该构建会自动由Github(组织范围内)的Webhook触发.不需要特殊的Github Organization插件.

The builds automatically get triggered by Github (organization-wide) webhook if the URL matches that of any of the repositories. No special Github Organization plugin is needed.

这篇关于Github组织中所有存储库的单一詹金斯工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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